4

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

Deleted User
  • 2,551
  • 1
  • 11
  • 18
user3804654
  • 51
  • 1
  • 8

3 Answers3

3

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
andrade
  • 156
  • 8
0

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
}
perreal
  • 94,503
  • 21
  • 155
  • 181
  • You might want to test this. I don't think aliases are passed through to at. – John C Jul 09 '14 at 05:26
  • @JohnC: It's a function, not an alias. But you're right that `at` won't be able to see it. More to the point, the solution to this problem is `cron`, not `at` – rici Jul 09 '14 at 05:29
  • @JohnC, yes it is a function but same can be achieved via a script in `bin` for example. And surely `cron` is the right tool. – perreal Jul 09 '14 at 05:31
0

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
kpater87
  • 1,190
  • 12
  • 31