0

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.

2
  • You need: superuser.com/questions/448445/… Commented 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? Commented Jan 22, 2016 at 11:24

2 Answers 2

1

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.

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

2 Comments

Thanks but I tried your method, It throws a permission denied exception. therefore I cannot use disown too.
what to do if we dont have a job but a process , i can run it in bg by & but when i close terminal, it also stops, how can i disown that
0

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.

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.