Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote script execution problem 1

Status
Not open for further replies.

mrmac228

IS-IT--Management
May 27, 2003
255
GB
I have two systems and I need to exectute a script on one from the other (ultimately from another script). The problem I have is that the script on the remote machine is in /sbin/init.d and I cant change it and the script runs a command in the background. When I issue the command "rsh <host> /sbin/init.d/appstart start" the command hangs, but the process is started on the remote system. However the rsh does not finish due to the & in the start script which is not what I want.

The command in the /sbin/init.d/appstart script needs to have the & otherwise it would hang when it was booting that system.

Anyone any suggestions on how I can run the script on the remote system and yet get the rsh command on the local system to return?


The script looks like:
Code:
#!/sbin/sh

#####################################################################
# Variables
#####################################################################

# config path
CONFIG_PATH=<config file path>
export CONFIG_PATH

# Path to shared libraries
LD_LIBRARY_PATH=<shared lib path>
export LD_LIBRARY_PATH

#####################################################################
# Code
#####################################################################

case "$1" in
'start')
   echo "Starting <APP>..."

   if /usr/bin/app&; then
      echo "APP started"
   else
      echo "Cannot start APP"
   fi

   ;;
'stop')
   echo "Stopping APP..."

   while :
   do
      PID=`ps -eo pid,cmd | grep /usr/bin/app | grep -v grep | awk '{print $1}'`
      if [ -n "$PID" ]
      then
         kill -TERM $PID
      else
         exit 0
      fi
      sleep 1
   done
   ;;
*)
   echo "usage: $0 {start|stop}"
   ;;
esac

I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams
 
PS I dont want to run the rsh command in the background (rsh <remote host> "/sbin/init.d/appstart start" &) on the local machine as it will leave two rsh processes running on the local machine.

I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams
 
Why not using the exec shell builtin in your rsh command line ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

the following command still hangs the shell on the local machine.

rsh <remote host> exec "/sbin/init.d/appstart start"



I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams
 
And something like this ?
rsh <remote host> "echo '/sbin/init.d/appstart start' | at now"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That does it!

You must be pretty damn good at lateral thinking puzzles as well!

Thanks and a star.

I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top