Running backend processes in ssh

Hi Team,
i have a script alloc.sh on server1

main () {
if [ "$1" == "REQUEST" ] ; then
    (nohup ./alloc.sh ALLOCATE 5400 isogen_alloc_$2 < /dev/null 2> /dev/null &)
    echo ALLOC_OK
    exit 0
fi
if [ "$1" == "ALLOCATE" ] ; then
    sleep $2
fi
}
main $@

Here if i execute the alloc.sh on server1, it gets executed successfully.
purpose of this script is to run a process in background for 5400 seconds for monitoring reservation of server1 for some purpose.

But the problem here is, if i execute the same script from server2(where passwordless to server1 is enabled),

On Server2:
ssh root@server1 './alloc.sh REQUEST ABC_123456'
ALLOC_OK
<it'll come out after the sleep time>

the script is not going for background.!

Could you pls check why the command (nohup ./alloc.sh ALLOCATE 5400 isogen_alloc_$2 < /dev/null 2> /dev/null &) is not working as expected when i call this from server2.

Regards,
Chandana

Run your script like that.

Method 1:

nohup yourscript.sh &

Method 2:
- start the process from console
- send it to background CTRL + Z
- then disown -a

1 Like