Solved

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

Posted on 2013-12-20
2
1,018 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now