Issue
i have a problem, plese watch this code. (j_restart.sh file)
#!/bin/bash
printf "Killing j-Chat server script... "
nyret=`pkill -f index.php`
printf "OK !\n"
printf "Wait killing instances."
while : ; do
nyret=`netstat -ap | grep :8008 | wc -l`
if [ "$nyret" == "0" ]; then
printf "OK !\n"
break
fi
printf "."
sleep 3
done
echo "Runing j-Chat server script... "
nyret=`nohup php -q /home/jChat/public_html/index.php < /dev/null &`
echo "OK !"
echo "j-Chat Server Working ON !";
ssh return val :
root@server [~]# sh /home/jChat/public_html/j_restart.sh
Killing jChat Server Script... OK !
Wait killing instances................ OK !
Runing jChat Server Script...
nohup: redirecting stderr to stdout
(and waiting not jump next line..)
im press manualy ctrl+c keys
^C
root@server [~]#
How to fix this problem ? why not working complete ? Stop and wait line 16...how to countinue next line 17 and 18... ?? Help me please..
Solution
Here's a simpler example reproducing your problem:
nyret=`nohup sleep 30 < /dev/null &`
echo "This doesn't run (until sleep exits)"
The problem is the shell is waiting to capture all output from your command. It runs in the background, but it still keeps the pipe open, so the shell waits.
The solution is to not capture the output, because you don't use it anyways:
nohup sleep 30 < /dev/null &
echo "This runs fine"
Answered By - that other guy Answer Checked By - David Marino (WPSolving Volunteer)