A script that keeps updating the log file. data like system time and date, users currently logged in etc for every interval of time say 5 minutes. THE SCRIPT MUST RUN EVEN AFTER THE TERMINAL HAS BEEN CLOSED.
-
You need: superuser.com/questions/448445/…Identity1– Identity12016-01-22 10:24:35 +00:00Commented Jan 22, 2016 at 10:24
-
Well that command is not executing in my CLI. Or I duno where to place that command. Inside the script file or in the prompt or where?Bala Krishnan– Bala Krishnan2016-01-22 11:24:11 +00:00Commented Jan 22, 2016 at 11:24
2 Answers
Actually, no.
First of, you don't need sh:
$ ./newscript.sh &
This is enough. This will start a background process. But your terminal is still controlling it. To achieve the behavior you want, do this:
$ disown %1
This will disown the job with the jobspec 1 (which is like an id), which was the one you started beforehand. Now you can close the terminal.
2 Comments
Hurrah!! I would like to answer my question since i have got the solution.
For example, I'm running a script newscript.sh I want to run this in background and continue someother job in the terminal or i can close the terminal.
[yourname @ username ~]$ sh newscript.sh &
and hit enter. You will get a PID and your job will be attached to the background.
To kill the same process, use the PID
For eg., kill 1205212
Thank you.