Solved

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

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

759 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

18 Experts available now in Live!

Get 1:1 Help Now