1

I have one central machine and multiple remote machines. Configured passwordless connections to remote machines from central machine.

I have to login from central vm to remote vm's and execute script in remote vm's

Below is the example, what i am trying

Central Machine:

#!/bin/sh
ssh root@remotemachine1
#run runscript.py in remotemachine1
ssh root@remotemachine2
#run runscript.py in remotemachine2

Remote Machine

python runscript.py

runscript.py

device = ["device1","device2","device3"]
for i, x enumerate(device):
    print "{}. {}".format(i+1, x)
select_device = raw_input("Choose Device: ")
print "You Selected Device {}".format(device[int(select_device) - 1])
do something
....
....
....
....

repeat = raw_input("Do you want to repeat? Y/N:")
do something
........
........
........

Someone help me how to login and run script in remote1 machine and exit from remote1 machine and run script in remote2 machine.

meteor23
  • 267
  • 3
  • 6
  • 11

1 Answers1

2

You can run the following command

ssh  $DEST_USER@$DEST_MACHINE "python -u path_to_your_script.py"

If your script is not there, please make sure you upload script using scp first and then execute above command.

device = ["device1","device2","device3"]
for i, x in enumerate(device):**
    print ("{}. {}".format(i+1, x))
select_device = raw_input("Choose Device: ")
print "You Selected Device {}".format(device[int(select_device) - 1])
Vikram Patil
  • 628
  • 6
  • 20