Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a script at a certain time on Linux? [closed]

I have a text file containing a specific date and time. I want to be able to run a script at the time specified in that file. How would you achieve that? Create another script that runs in background (sort of a deamon) and checks every second if the current time is matching the time in the file? Is there another way? The machine is a linux server , Debian wheezy. Thanks in advance

like image 969
Aaron Ullal Avatar asked Sep 22 '13 15:09

Aaron Ullal


People also ask

How do I run a script at a specific time in Linux?

Here, by using an asterisk in the last three fields (1-31 days, 1-12 months, all days of the week), our backups.sh script will run every day at 3 pm. In the above expression, 2-50/10 in the minute field indicates the second minute of the hour and every 10 minutes thereafter.

What should I do to run a script on specific time without cron?

If not using cron, you will have to arrange for the script to re-execute itself at a particular time in the future, maybe using at (which is part of cron), or by sleeping (which would make the executions drift over time), and you would additionally have to set up an initial execution of the script at reboots (again, ...

How do you schedule a shell script in Unix without crontab?

the_main_thing is the command or script you want to run periodically. The purpose of [[ $0 = /* ]] && script=$0 || script=$PWD/$0 is to get the absolute path of the current script itself.


1 Answers

Look at the following:

echo "ls -l" | at 07:00 

This code line executes "ls -l" at a specific time. This is an example of executing something (a command in my example) at a specific time. "at" is the command you were really looking for. You can read the specifications here:

http://manpages.ubuntu.com/manpages/precise/en/man1/at.1posix.html http://manpages.ubuntu.com/manpages/xenial/man1/at.1posix.html

Hope it helps!

like image 155
Antoni Avatar answered Oct 19 '22 11:10

Antoni