I set up to run notify-send every minute,
$ crontab -l 1 * * * * /usr/bin/notify-send -t 0 "hello"
Why does it not work? Do I need to restart OS after editing the crontab file?
Does the following mean that
$ ps aux | grep -i cron root 1038 0.0 0.0 23660 2420 ? Ss Apr20 0:00 cron
Can I specify a more frequent schedule, such as 30 seconds? Can the time be specified as decimals?
0.5 * * * * /usr/bin/notify-send -t 0 "hello"
Your first problem is that you have the wrong syntax for running a job every minute:
1 * * * * /usr/bin/notify-send -t 0 "hello"
1 in the first field means that the job runs only at 1 minute after each hour. Change it from
* * * * * /usr/bin/notify-send -t 0 "hello"
The second problem is that cron jobs run in a very limited environment. On my system (Linux Mint), the only environment variables that are set are
$PWD -- and
$PATH is normally set to
At the very least, the lack of a setting for
$DISPLAY means that
notify-send can't display anything.
A quick experiment with:
* * * * * DISPLAY=:0.0 notify-send "hello from crontab"
resulted in this error:
(notify-send:18831): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
(I'm running the Gnome desktop.)
In another experiment, I copied my entire interactive environment into a script, then edited the script so it sets all the environment variables explicitly and invokes
notify-send. That actually works; I'm now getting a pop-up "hello from crontab" message every minute.
I'm certain that I don't need all my interactive environment for this to work, but I don't know exactly which environment variables are needed or what their values need to be. It's very likely that some of the needed variables are set when the current login session is started, and that they'll change if I logout and login again. It's also very likely that the details will vary depending on which desktop environment you're using.
This is not a complete solution, but it should give you a starting point -- and perhaps someone else can add the relevant details.
cron job almost certainly is running. However, you cannot (easily) interact with your GUI from
cron so unfortunately
notify-send will fail.
You can prove whether or not your
cron job is running by modifying the
crontab line as follows
1 * * * * ( date; notify-send /usr/bin/notify-send -t 0 "hello"; echo ) >>cron.log 2>&1
This will write the date and any output from the
notify-send command to a log file called
cron.log in your home directory.
Please note, however, that as copied from your question this will only run at the first minute of every hour (
1 * * * *). To run every minute you would need to use
* * * * * ("every minute" instead of "1st minute"). Kudos to @KeithThompson for pointing this out.
The granularity of
cron is one minute. If you need to run a job more frequently than this you may want to consider either a standalone daemon, or two lines in
cron one of which is preceded by
$ crontab -l */1 * * * * /usr/bin/notify-send -t 0 "hello"
try this if you want to run your
cron every minute.