Operating System - Linux
1752489 Members
5703 Online
108788 Solutions
New Discussion юеВ

need help with embedded script within remote shell script

 
SOLVED
Go to solution
Matt Shaffer_1
Regular Advisor

need help with embedded script within remote shell script

I have a remote script (rsh) that is going out to multiple locations and doing multiple jobs. The last thing that it does is copy out a script to the remote location and then execute the script. This embedded script takes about 1.5 hours to run so I want my main script to copy over this script, execute it but then move on and loop through again, hitting the next location in the list. Is this possible?
7 REPLIES 7
David Kiel
New Member

Re: need help with embedded script within remote shell script

If you don't need to monitor the output from the remote location you could use

rsh remotehost "at -f script now"

to start the remote job without waiting.
renarios
Trusted Contributor

Re: need help with embedded script within remote shell script

Hi Matt,

You could start scripts in the background using the ampersant sign (&). For example:

for i in srv1 srv2 srv3
do
rsh ${i} .... &
done
, or for the readability do it with functions:

function remote_script
{
#do the things you want to do
)

for i in srv1 srv2 srv3
do
remote_script &
done

Cheers,

Renarios
Nothing is more successfull as failure
Bill Thorsteinson
Honored Contributor

Re: need help with embedded script within remote shell script

Have you looked at something like cfengine.
You could have it copy and execute the
script.
Matt Shaffer_1
Regular Advisor

Re: need help with embedded script within remote shell script

I tried the "&" idea before and that does not work. I think the at -f will work although I haven't done a full blown test yet.
Muthukumar_5
Honored Contributor

Re: need help with embedded script within remote shell script

You try as,

for server in "server1 server2 server3"
do

remsh -l root ${server} -n "script" 1>&- 2>&- &

done

It will do it. &- is used to close error and output mode. Else it will interact with other shell execution.

--
Muthu
Easy to suggest when don't know about the problem!
renarios
Trusted Contributor
Solution

Re: need help with embedded script within remote shell script

Hi Matt,

I tried the following and it works OK

function rem_dbcheck
{
ssh ${i} -n /home/oracle/rene/dbstatus.sh
}

for i in srv1 srv2 srv3 srv4
do
rem_dbcheck 1>/tmp/db.log 2>&1 &
done

Cheers,
Renarios
Nothing is more successfull as failure
Matt Shaffer_1
Regular Advisor

Re: need help with embedded script within remote shell script

. using & to run it in the background worked. i'm sure i had my syntax wrong or something. didn't know much 5 years ago.