ksh shell script doesn't wait for the background processes if executed remotely via ssh
Issue
- Consider following script on remote server:
$ cat test.sh
#!/bin/ksh
echo "`date` : EXECUTING $0 on `hostname`"
grep -ri "TEST" /* >> ~/test.out &
echo "`date` : FINISHED $0 on `hostname`"
and local script:
$ cat testwait.sh
#!/bin/ksh
for i in localhost
do
ssh $i ~/test.sh &
done
wait
echo "FINISHED"
which executes test.sh remotely via ssh.
- If you are running the script in RHEL 5.4 and higher, it shows following output:
$ ksh testwait.sh
user@localhost's password:
Tue Feb 11 16:25:58 EST 2014 : EXECUTING /home/user/test.sh on localhost.localdomain
Tue Feb 11 16:25:58 EST 2014 : FINISHED /home/user/test.sh on localhost.localdomain
FINISHED
and exits immediately.
- On RHEL 5.3, the progress of grep is shown:
$ ksh testwait.sh
user@localhost's password:
Tue Feb 11 17:01:09 EST 2014 : EXECUTING /home/user/test.sh on localhost.localdomain
Tue Feb 11 17:01:09 EST 2014 : FINISHED /home/user/test.sh on localhost.localdomain
grep: /dev/vsock: Invalid argument
grep: /dev/vmci: Invalid argument
grep: /dev/gpmctl: No such device or address
grep: /dev/log: No such device or address
...
...
FINISHED
and script waits until grep finishes.
Environment
- Red Hat Enterprise Linux (RHEL) 5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.