trap "" HUP v.s Nohup ? How can I run a portion of shell script in nohub mode?

Posted by Alex on Server Fault See other posts from Server Fault or by Alex
Published on 2012-11-13T15:21:30Z Indexed on 2012/11/13 17:02 UTC
Read the original article Hit count: 326

I want to run a shell script over the weekend, but I wanna make sure if the terminal loses the connection, my script won't be terminated. I use nohup for the whole script invokation, but I also want to execute some portion of my shell script in a way that if someone closes my terminal, my script runs on the background still. Here is a simple example :

#!/bin/bash

echo "Start the trap" 
trap " " HUP 
echo "Sleeping for 60 Seconds"
sleep 60 echo "I just woke up!"

Please suggest what I should do ? The trap " " HUP seems like not working when I close my terminal tab.

© Server Fault or respective owner

Related posts about screen

Related posts about shell-scripting