# # Running a command at a particular time
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Running a command at a particular time

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© August 2015 Anthony Lawrence

Anonymous asks:

I have a cron job that runs every hour. Within that script I need to test for specific times. For example, if today is the 27th and it is 4 AM, I need to run another script.

Of course you could do this with separate cron jobs, but if you want to maintain one script that you'll run hourly, it would look something like this:


#!/bin/bash
DOM=`date +%d`
HR=`date +%H`
if [ $DOM -eq 27 ]
then
  if [ $HR -eq 05 ]
  then 
  echo foo
  yourcommand
  fi
fi
 

Most of us wouldn't write it like that, though. We'd do:

#!/bin/bash
DOM=`date +%d`
HR=`date +%H`
if [ $DOM -eq 27 -a $HR -eq 04 ]
then
  echo foo
  yourcommand
fi
 

Watch your spacing - can't do "if [$HR -eq 05 ]" (no space after "[").


If you found something useful today, please consider a small donation.



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> Running a command at a particular time


Inexpensive and informative Apple related e-books:

Take Control of iCloud, Fifth Edition

Take Control of iCloud

Take Control of the Mac Command Line with Terminal, Second Edition

Take Control of IOS 11

Take control of Apple TV, Second Edition





More Articles by © Anthony Lawrence





Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us


Printer Friendly Version





Technology is a word that describes something that doesn’t work yet. (Douglas Adams)




Linux posts

Troubleshooting posts


This post tagged:

Bash

Forum

Scripting

Shell



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode