HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Spawning a Process in different server

 
pareshan
Regular Advisor

Spawning a Process in different server

I am writting a script which generates reports collecting data from many servers.

I am supposed to get data for one of the column of the report by running one (script) command in all the servers but the problem is it takes like 30 second. So when i do

ssh $i /usr/bin/status| grep super|awk '{print $7}' > super_info

it gives me the desired output but it waits for 30 seconds in each server for that script to get completed.

That command/script is present in each server,Is there any way not to wait for that script completion and do other things until that gets completed and gives the data.

I appreciate any help
thanks in advance

8 REPLIES

Re: Spawning a Process in different server

You could put the script in the background. Or even the ssh. (You probably want to use "ssh -n".) If more then one server, you would need different output files.
James R. Ferguson
Acclaimed Contributor

Re: Spawning a Process in different server

Hi:

In addition to adding the '-n' switch and running the script in the background as Dennis suggested, do your server a favor and eliminate the useless 'grep' process:

# ssh -n ${i} /usr/bin/status|awk '/super/ {print $7}' > super_info

Regards!

...JRF...
pareshan
Regular Advisor

Re: Spawning a Process in different server

so how can i run my ssh in background

I tried putting & but it doesnt work

Also, that means there is no other way than running it in background?
pareshan
Regular Advisor

Re: Spawning a Process in different server


I have tried .............

# ssh -n ${i} /usr/bin/status|awk '/super/ {print $7}' > super_info

got following error

syntax error The source line is 1.
The error context is
/superdome{print >>> $7} <<<
awk: Quitting
The source line is 1.
Note: No action specified. Default behavior is display all.
syntax error The source line is 1.
The error context is
/super{print >>> $7} <<<
awk: Quitting
The source line is 1.


Michael Steele_2
Honored Contributor

Re: Spawning a Process in different server

This problem will exist across the board with any remote login using a standard command interpreter like posix, ksh with awk and ssh. The only way you might speed it up is with perl, which processes much faster.

Some of the other posters suggested copying the script over to each machine for execution and then emailing the report in, this also will speed things up. As will any minimizing of processing remotely over the network.
Support Fatherhood - Stop Family Law
James R. Ferguson
Acclaimed Contributor

Re: Spawning a Process in different server

Hi:

# i=somehostname
# ssh -n ${i} /usr/bin/status|awk '/super/ {print $7}' > super_info &

...will run in the background.

Regards!

...JRF...

Re: Spawning a Process in different server

># ssh -n ${i} /usr/bin/status | awk '/super/ {print $7}' > super_info
>got following error
syntax error The source line is 1.
The error context is
/superdome{print >>> $7} <<<

This seems to indicate that you used:
awk '/superdome {print $7}' > super_info

And lost the last "/" in the ERE.
Bill Hassell
Honored Contributor

Re: Spawning a Process in different server

You are running the status command on the remote machine but transferring all that data back to the local machine for grep and awk processing. All remote commands stop at the first pipe or redirection. Change your command to something like this:

ssh $i "/usr/bin/status | awk '/super/{print $7}'" > super_info

Now the poutput of status is processed through awk on the remote machine and only the answer is returned to be redirected to your local file.


Bill Hassell, sysadmin