How to do ssh and scp from linux server to Windows - linux

I want to understand how can we do ssh and scp from linux server to windows server. Can we simply run ssh and scp command like below from linux server.
ssh user#IPaddressWindowsserver
scp /home/ubuntu/myfile username#IP_of_windows_machine:/C:/Users/Anshul/Desktop.
I also want to execute these commands from jenkins pipeline script, I am using windows as my node in jenkins.
Can I simply run like below using bat script.
bat 'ssh user#IPaddressWindowsserver'
bat 'scp /home/ubuntu/myfile username#IP_of_windows_machine:/C:/Users/Anshul/Desktop'
Note:- I want to do ssh from linux to windows only, not the other way round.

Related

Execute bash script on a remote-linux

I have a bash script lets say test.sh. This script contains the following:
#!/bin/bash
echo "khaled"
ads2 svcd&
This script simply prints my name (just for test purposes) and execute ads-service application in the background. When i run the script on my ubuntu, it works correctly. As a test i checked which programs run on the kernel
As you see. ads2 runs and has 12319 process-id.
Now what I'm trying to do is to run the script on the ubuntu, however remotely from a windows pc.
Therefore i opened command-line on windows and executed the following command:
ssh nvidia#ubuntu ip-address ~/test.sh
And i get the following
As you see the scripts run and prints khaled,however on windows command line and what i want is that the script is executed on the ubuntu. this justify why the lineads2 svcd& doe not do anything, neither on windows (which makes sense, since ads2 is installed on ubuntu) nor on linux.
So how can i execute the script on ubuntu ?
thanks in advance
Use the full path to start ads2. When using remote SSH your environment variables may be different than in a local shell.
#!/bin/bash
echo "khaled"
/home/nvidia/ads2 svcd&
Not sure where ads2 is located.
Try the following to locate it on your Ubuntu local shell.
command -v ads2
You may also need nohup to persist the process beyond the life of the SSH session.
If you have the script on the remote server and you want to run this, you would add back ticks,
ssh user#server './test/file.sh'
The script's output would be sent to your local machine, as if you ran the command from your local machine.

python script to SSH into remote computer and run command

i'm new to python3 and scripting. I've got 2 commands I need to write a script for. what i'm looking to do is ssh into a remote computer and run a command.
i've tested it manually and works fine but i'd need to put it in a script. Thanks for any help in advance.
sshpass -p 'SecretPassword' ssh user#10.X.X.X
run a local command on remote computer
Bartibog

Send shell script to linux machine remotely

I have a web application that generates a shell script with commands running on a server.
Then I also have another Linux server where the script should be executed.
I was wondering if someone could point me in the right direction in terms of how I could send a shell script from one server to another linux server and execute it on the second server?
You can use scp to transfer the file over
scp <source_file> <destination>
if your destination is the host in question:
scp myfile.sh username#x.x.x.x:/path/to/new/script.sh
For executing on the server, you have various options. You can use a cron job to execute it periodically. You can use rc.local to execute at startup. You can use ssh.
Lets take SSH as an example:
ssh username#x.x.x.x 'sh /path/to/script.sh'
The above ssh command will run myfile.txt on the server.
for linux machines easiest way is
ssh root#MachineB 'bash -s' < local_script.sh
as explained in Jason R. Coombs's answer

to ssh and scp in one script

I perform ssh to remote server to run a backup script. Then scp it to local machine.
1. ssh root#Remoteserverip sh ~/folder/backupscript.sh
2. scp root#Remoteserverip:/backupfolder/file.tgz /localfolder/
Is there any way to script these two operations in one script?
Ps: couldn't find solution elsewhere.
Why not? Just put those commands in the script and thats it.
ssh root#Remoteserverip sh ~/folder/backupscript.sh
scp root#Remoteserverip:/backupfolder/file.tgz /localfolder/

Linux: Run a shell command remotely and print result

I want to create a script that runs shell commands on a remote Linux machine and print out the result. Some thing like a "run once" SSH. Or for those familiar with Android development, something like "adb shell". For example, I want to run "ls" on my remote machine and display the results on the local host.
This is supported directly by ssh:
ssh [options] [user#]hostname [command]
eg
ssh user#host ls
If not command is given an interactive shell is usually run by default.

Resources