Command to execute a script later

Viewed 139

I would like to execute a script after 12 hours. I could execute the script by remote access, but problem is I will be travelling by flight and may not have internet access. So I was wondering if there is some command to execute a script after few hours or at some specific time. e.g.,

cat my_script.sh
echo Hello World
run my_script.sh at 23:00 hr
4 Answers

Take a look at the man page for at

man at

There are lots of ways you can specify the time. You can do something like:

at -f my_script.sh 23:00

Use cron job in linux. like

0 */12 1 11 3 /bin/execute/my/script.sh >/dev/null 2>&1
#!/usr/bin/python
import time
time.sleep(60*60*12)
# your script here

# for shell script:
import subprocess
subprocess.call(['./my_script_name.sh'])

For anyone who doesn't have a ton of experience with shell scripts, make sure your .sh script has a shebang line at the top of the script #!/usr/bin/env bash and that it's executable with $ chmod 744 my_script.sh

I would recommend using either cron or at for this kind of operation. If you need to run the job only one single time then at would be the most straightforward option.

If you prefer to run it on a recurrent basis/schedule (e.g. if you need it to run every night) it with more flexibility cron is the tool you are looking for.

Have a safe trip!

Related