Execute a shell script everyday at specific time
You want to edit your crontab file using
crontab -e
Then you want to add
55 23 * * * COMMAND TO BE EXECUTED
for more info look at this
How to run a script at a certain time on Linux?
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!
Run CRON job everyday at specific time
Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an on-going basis.
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
Example::Scheduling a Job For a Specific Time
The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.
Please note that the time field uses 24 hours format. So, for 8 AM use
8, and for 8 PM use 20.
30 08 10 06 * /home/yourname/full-backup
- 30 – 30th Minute
- 08 – 08 AM
- 10 – 10th Day
- 06 – 6th Month (June)
- *– Every day of the week
In your case, for 2.30PM
,
30 14 * * * YOURCMD
- 30 – 30th Minute
- 14 – 2PM
- *– Every day
- *– Every month
- *– Every day of the week
To know more about cron, visit this website.
How to run the shell script in cron job in specific time at only once per day
The crontab you've listed means;
* 9 * * *
> At every minute past hour 9
You'l need 0 9 * * *
since you only want to job to run on the whole our, hence the 0
minutes.
0 9 * * *
> At 09:00
Use something like crontab.guru to visualize it.
Run a command at a specific time
You could try this:
at 1843 <<_EOF_
php /run/this/script.php
_EOF_
edit if what you want to do is run Firefox, try this:
at 1843 <<_EOF_
DISPLAY=:0.0 /usr/bin/firefox
_EOF_
How can I make a bash command run periodically?
If you want to run a command periodically, there's 3 ways :
- using the
crontab
command ex.* * * * * command
(run every minutes) - using a loop like :
while true; do ./my_script.sh; sleep 60; done
(not precise) - using systemd timer
See cron
Some pointers for best bash scripting practices :
http://mywiki.wooledge.org/BashFAQ
Guide: http://mywiki.wooledge.org/BashGuide
ref: http://www.gnu.org/software/bash/manual/bash.html
http://wiki.bash-hackers.org/
USE MORE QUOTES!: http://www.grymoire.com/Unix/Quote.html
Scripts and more: http://www.shelldorado.com/
Shell infinite loop to execute at specific time
Check the time in the loop, and then sleep for a minute if it's not the time you want.
while :
do
if [ $(date '+%H%M') = '0600' ]
then /home/sas_api_emailer.sh |& tee first_sas_api
fi
sleep 60
done
Running a shell script once a day at random time
The best alternative to cron
is probably at
- See
at
man page
Usually, at
reads commands from standard input, but you can give a file of jobs with -f
.
Time wise, you can specify many formats. Maybe in your case the most convenient would be
at -f jobs now + xxx minutes
where your scripts gives xxx as a random value from 1
to 1440
(1440 minutes in a day), and jobs
contains the commands you want to be executed.
Related Topics
Create a Static Haskell Linux Executable
How Do Linux File Descriptor Limits Work
Equivalent of Ctrl C in Command to Cancel a Program
How to Wait for First Command to Finish
How to Find Substring Inside a String (Or How to Grep a Variable)
Capturing Rscript Errors in an Output File
How to Get the Architecture of a '.A' File
Difference Between Two .Tar.Gz File Lists on Linux
Use Bash to Read a File and Then Execute a Command from the Words Extracted
Creating PDF Invoices - Are There Any Templating Solutions
How to Automate HTML-To-Pdf Conversions
Logrotate to Clean Up Date Stamped Files
How to Parse Netstat Command in Order to Get Process Name and Pid from It
Linux - Understanding the Mount Namespace & Clone Clone_Newns Flag