1

I have a file containing 302 commands that start process on our server. Staring them all at once would kill it, so I have a script that pushes one command to the shell, waits for the process to finish and then calls the next.

This whole process will probably take a day or so to complete, and I'd like to log off in between. I know there's nohup or, if you forget that at the beginning, disown to make sure a process will still run even if you close the connection, but I'm not sure where I should put that call in my case. Only the script that channels the commands; only on the commands; or on both?

I apologize if this is a silly question, but I couldn't find a simple answer to exactly that question online and I can't risk disrupting these processes just because I got something wrong.

bobs
  • 21,844
  • 12
  • 67
  • 78
Lilith-Elina
  • 1,613
  • 4
  • 20
  • 31
  • Linux batch?? Do you mean a bash shell script? I don't even want to begin asking why you have a script that runs 302 processes. – PenguinCoder Jan 11 '13 at 15:03
  • can't you make "system_root" start the script? also you can change ownership @root who stays logged in all the time the machine is turned on – Vogel612 Jan 11 '13 at 15:06
  • http://stackoverflow.com/questions/3099092/why-cant-i-use-unix-nohup-with-bash-for-loop?rq=1 has examples you can use. Sounds like @msw would work for you. – slimdrive Jan 11 '13 at 15:12

2 Answers2

2

Sure you can use nohup:

nohup <script name> &

You can execute this command and the safely logout. You can then log back in and use ps command to see if your script is still running. I would also create a log file to be able to monitor the progress and redirect all standard and error output to that file.

shargors
  • 2,147
  • 1
  • 15
  • 21
  • In bash one can simply do `( – Maxim Egorushkin Jan 11 '13 at 16:48
  • @Maxim Yegorushkin - That will kill process if you logout from term. – Satish Jan 11 '13 at 17:52
  • 1
    It will also create nohup.out file in current directory, so you can see progress of script. – Satish Jan 11 '13 at 17:56
  • @Satish This expression is called shell escape, if memory serves me right. What happens is that it starts a sub-shell, the sub-shell starts the command in the background and quits. The command gets orphaned and changes its parent to be init or systemd (pid 1) process. This way the command doesn't receive `SIGHUP` or any other signal from the shell. – Maxim Egorushkin Jan 12 '13 at 13:13
  • @Sitish `( – Maxim Egorushkin Jan 12 '13 at 13:14
  • Thank you for the reassurance, I'll try it later today. :) – Lilith-Elina Jan 14 '13 at 13:52
  • If I run any other commands in the script after "nohup" ( like tail -f nohup.out, etc..), the process I start with nohup gets killed if I do CTRL+C. I wonder why that is.. I am using RHEL6/bash. – Soichi Hayashi Jan 23 '15 at 13:01
0

you could schedule you script to run, so that you don't have to be connected to the server while the process runs. see cron help: http://www.scrounge.org/linux/cron.html

Satish
  • 16,544
  • 29
  • 93
  • 149
will
  • 312
  • 3
  • 9