I created a simple crontab job.
It should execute every 15 minutes to alert me that I need to take a short break. However, it does not work. I don't know why.
Please help me if you have experience with crontab. I used the command crontab -e to create this file and save it.
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
*/15 * * * * /home/galaxy/Documents/projects/Bash/cron_job.sh
This file is supposed to execute the script cron_job.sh every 15 minutes.
This is a Bash shell script that has a chmod value of 500. It contains one command to create a new gnome-terminal and immediately run a command inside that new terminal to cat the file take_a_break. That is a text file with a simple message telling me to take a break.
Running from the terminal directly either the shell script or just running the command contained inside of it works flawlessly, but the crontab job does not work at all. Maybe I formatted something incorrectly.
Here is the contents of the file cron_job.sh:
#!/bin/bash
gnome-terminal -e "bash -c \"cat /home/galaxy/Documents/ascii/take_a_break; exec bash\""
The reason I put the command inside a shell script is because cron did not run it previously, but cron also does not run the shell script.
I checked and it seems to me that I have the correct syntax.
Also if it is relevant, trying to run the crond
command gives an error:
$ crond
No command 'crond' found, did you mean:
Command 'cron' from package 'cron' (main)
crond: command not found
gnome-terminal
might solve it. 2) Can you run the command/home/galaxy/Documents/projects/Bash/cron_job.sh
on its own and does it do what you want? – Julie Pelletier Mar 16 '17 at 02:51crontab
file with the syntax here. Your actual command is sufficient. Also note that troubleshooting involves simplifying everything and therefore testing something likedate > /tmp/lastbreak
as the job would allow you to see very easily if it actually runs or not. – Julie Pelletier Mar 16 '17 at 02:54DISPLAY
variable. – steeldriver Mar 16 '17 at 03:04type gnome-terminal
will show you the full path. steeldriver is right about other environment variables that will need to be set. – Julie Pelletier Mar 16 '17 at 03:12