0

I would like to execute a script after 5 hours. My script is

$cat << EOF > run.sh
sleep 18000
sh run_my_script.sh
EOF

I submitted the job as:

sh run.sh >& log &

But due to some problem the server got shutdown.

My question is what will happen to my job:

1- Whether my job got deleted and I will have to submit the job again?
2- Server reboot within 5 hours. Will job still valid and start at 5 hours?
3- Server reboot after 5 hours.
3
  • Are you running the 2 commands from a shell prompt?
    – GMaster
    Sep 26, 2022 at 6:46
  • No, these commands are inside another script e.g. "run.sh". I have edited the question. Thank you.
    – Kay
    Sep 26, 2022 at 6:48
  • Strange question because on shutdown all procceses are gone. Jobs is a shell feature so when your shell process is gone all jobs are gone too.
    – gapsf
    Sep 27, 2022 at 4:22

2 Answers 2

2

1- if the job gets deleted, you will have to submit job again. The sleep command will be killed so how much time elapsed will be lost

2- If servers gets rebooted before 18000 seconds have passed, job will be invalid

3- run_my_script.sh will run in this case

Consider using cron

3
  • You can simulate the 3 scenarios yourself by using a smaller timeframe, like a few minutes instead of 5 hours
    – GMaster
    Sep 26, 2022 at 6:54
  • The 3-run_my_script.sh will run in this case is not clear. If it will run, then how job will be invalid if server reboot before 5 hours. I can check it in my own linux system. But my question was for remote hpc.
    – Kay
    Sep 26, 2022 at 6:59
  • I assumed server reboot after 5 hours means it will run more than 5 hours. Anyway, if you mean server will reboot exactly after 5 hours, the sleep command will complete and the sh run_my_script.sh may get a chance to run before the server reboots. But it may not. (As mentioned, use cron, or at)
    – GMaster
    Sep 26, 2022 at 10:05
2

The sleep command will get killed on shutdown.

You should use at which will survive a reboot.

e.g.

echo "sh run_my_script.sh" | at now+5hours

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .