user3804654
user3804654

Reputation: 61

How to run "at" command every hour

how can I programm with the "at" command that below runs at 6:00,7.00,8:00,9:00,10:00 until 23.00

cmd = "echo /bin/everyhour | at 06:00"

regards gwaag

Upvotes: 4

Views: 3244

Answers (3)

kpater87
kpater87

Reputation: 1270

You can create a script which will call at command and later the right job. Following one will run a job every hour but with small modification you can also reach hours between 6:00 - 23:00:

at now + 1 hour -m -f ~/scheduledTask.sh

#do the job
~/job.sh

Then you are running this script at a given time using at command:

at 06:00 -m -f ~/scheduledTask.sh

Upvotes: 0

andrade
andrade

Reputation: 156

The at command is used to schedule commands to be executed once. For recurring executions I would suggest cron. Edit your crontab with crontab -e and add the follow line:

00 06-23 * * * /bin/everyhour

Upvotes: 3

perreal
perreal

Reputation: 97948

You can try putting this in your .bashrc, not tested though:

doer() {
  t=$(date +"%k")
  bin/everyhour
  if [[ $t < 24 && $t > 5 ]]; then
      echo doer | at now + 1 hour
  fi  
}
doer

or, this one keeps on working but only executes on specified interval:

doer() {
  t=$(date +"%k")
  if [[ $t < 24 && $t > 5 ]]; then
      bin/everyhour
  fi  
  echo doer | at now + 1 hour
}

Upvotes: 0

Related Questions