0

I am calling the expect script from bash script inside for loop using multithreading in it. The expect script does ssh login and call python script using nohup command for restarting host. But, after completing the restart, the control not returned to the bash script.

Shell script code:

for host in ${hosts[@]};
do
  ./b.exp $id $pswd $host &
done
wait
echo "Completed"

Expect script code:

set timeout -1
spawn ssh <server login>
send "nohup /loc/c.py $host\r"
send -- "exit\r"
expect eof

I am expecting after all the hosts restart completion, the script should print "Completed". But, it is not printing anything and I need to manually exit the execution.

Could someone please tell what wrong I am doing here?

1 Answer 1

0

nohup doesn't detach the terminal, you want to send

 nohup /loc/c.py $host &

where the & to run the job in the background is the significant change.

(Properly speaking $host should be quoted, too, but if you are sure it contains a single token without whitespace or wildcard characters, this should not matter. Similarly "${hosts[@]}" should have double quotes, but again, under the given conditions, this should be fine without quotes.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.