Execute a Shell Script Everyday at Specific Time

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

Sample Image

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
  1. 30 – 30th Minute
  2. 14 – 2PM
  3. *– Every day
  4. *– Every month
  5. *– 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



Leave a reply



Submit