4

I'm toying around with building an application to display messages on the screen on a desired intervals.

I want to use cron to achieve that and I am considering my options. The most naive approach would be to print the commands directly into crontab. Is that a bad idea?

Rinzwind
  • 309,379
Yotam
  • 1,468

2 Answers2

3

No, it is not bad to have a long list in crontab. cron executes in minutes at the shortest time frame so it is not in real time but you can also have your notices in real time (see below).


As an alternative option you can also use cron to run 1 script that executes all your different crontab lines you otherwise would have included in your crontab where that file is executes or checks all the different options you want to get notices from. That would also be easier to maintain: if you need a new task you add it to your script and you can check if that job is flawed from the script itself (cron can be rather picky).


Might I also suggest you also have a look at creating an upstart job. This would be more the Ubuntu way. This way you create a daemon or service that you can start and stop from command linel. Plus it would make your notices real time instead of periodically.

Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.

# Ubuntu upstart file at /etc/init/yourservice.conf

pre-start script
    mkdir -p /var/log/yourcompany/
end script

respawn
respawn limit 15 5

start on runlevel [2345]
stop on runlevel [06]

script
su - youruser -c "NODE_ENV=test exec /var/www/yourcompany/yourproject/yourservice.js 2>&1" >>  /var/log/yourcompany/yourservice.log
end script
Rinzwind
  • 309,379
0

Use gnome-schedule

enter image description here

It's intuitive, and it's easier to launch graphical applications from (doing that via cron requires some extra work) - just don't forget to mark the command as an X application one in the task configuration.

Homepage: http://gnome-schedule.sourceforge.net/

Sample use: http://www.liberiangeek.net/2011/04/schedule-a-job-to-automatically-put-ubuntu-into-sleep-or-hibernation-mode/

arrange
  • 15,219