Solved

Linux, remote scripts with ssh (spawn a new script)

Posted on 2013-12-20
2
1,026 Views
Last Modified: 2013-12-20
I got my remote script to work.  I appreciate everyone's help

I am using a putty app from Windows, and then I can use ssh to remotely start a script

and the output from the client program prints out on my putty screen and waits to print more messages (no keyboard is accepted, just print statements.

I am using this command to start the process

sshpass -p 'xxxx' ssh root@xxclnt2 /home/test

This is working successfully as I get something like:

sshpass -p 'xxxx' ssh root@xxclnt2 /home/test
output line 1
output line 2
output line 3 
...

Open in new window


I have a new issue

I want to do now is to run 10 of these ssh remote scripts from the same file

I do NOT want the out put to print on my screen.  I simply want it to run in the background without actually printing to a screen or device.  So I tried this

sshpass -p 'xxxx' ssh root@xxclnt2 /home/test > nul
sshpass -p 'xxxx' ssh root@xxclnt32 /home/test > nul

However, the script never actually gets to  the second line, since it is busy trying to perform the first one by putting the output of the command into nul

Is there any way to 'spawn' a command like this, so I can put multple lines such as this into a script

Thanks
0
Comment
Question by:Los Angeles1
2 Comments
 
LVL 6

Expert Comment

by:RaithZ
ID: 39732742
put them all on one line.. and put a semi-colon between them, and then put an & at the end of the command line.  This should cause the commands to all execute at once.

sshpass -p 'xxxx' ssh root@xxclnt2 /home/test > nul; sshpass -p 'xxxx' ssh root@xxclnt2 /home/test > nul &

Open in new window

0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39732770
The Linux "null" device is /dev/null, as opposed to Windows' "nul"

You can run scripts in the background by putting an ampersand & at the end of the call.

Unix/Linux has two output streams, stdout (1) and stderr (2). You should redirect both to get rid of both types of messages, "normal" and "error".

sshpass -p 'xxxx' ssh root@xxclnt2 /home/test > /dev/null 2>&1 &
sshpass -p 'xxxx' ssh root@xxclnt32 /home/test > /dev/null 2>&1 &

(2>&1 redirects stderr to the same destination as stdout, here: /dev/null)

RaithZ's solution will run only the last command (the one after the last semicolon) in background. An alternative could be:

(sshpass -p 'xxxx' ssh root@xxclnt2 /home/test ; sshpass -p 'xxxx' ssh root@xxclnt32 /home/test) > /dev/null 2>&1 &

This starts a subshell in the background where both commands are executed in.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question