Hi,
I'm using expect to ssh into remote machine (i know its not the best practice), and run script "script.sh".
This "script.sh" checks whether an other process (some another script) is running and if not, it runs it as some other user.
Heres the "script.sh"
Now the problem is that the "some_process" should run continuously, yet at the second check of running processes (the line with a comment in code) it is already not running.
From what I googled, the "nohup" command should keep it running even after logging out of the system, but apparently it doesn't.
I dont know what I'm doing wrong, any help will be appreciated
I'm using expect to ssh into remote machine (i know its not the best practice), and run script "script.sh".
This "script.sh" checks whether an other process (some another script) is running and if not, it runs it as some other user.
Code:
#!/bin/bash
/usr/bin/expect << EOD
set timeout 2
spawn ssh "$user@$host"
sleep 2
expect "*assword:"
send "$passwd\r"
expect ">"
send "/home/$user/script.sh\r"
sleep 2
expect ">"
send "exit\r"
EOD
Heres the "script.sh"
Code:
#!/bin/bash
if [ -z "$(pgrep some_process)" ]; then
echo "some_process not running.. Starting.."
echo "passwd" | su - user
nohup ./some_process &
echo "PS : $(ps ax | grep some process)"
echo "passwd_of_original_user" | su - original_user
echo "PS : $(ps ax | grep some process)" #some_process is already not running at this line
else
echo "Some_process already running.."
fi
From what I googled, the "nohup" command should keep it running even after logging out of the system, but apparently it doesn't.
I dont know what I'm doing wrong, any help will be appreciated