2

I'm running Ubuntu16.
I'm trying to run very simple bash scripts and cron jobs!

I'm trying to get cron to run the following bash script on a daily basis:

#!/bin/bash
echo "Hello James how is your day going" 

I can run the script from the command line no problem, but cron won't? My Cron job is set up as such:

0 15 * * * /tmp/myjob.sh

What am I missing?

Yaron
  • 13,453

3 Answers3

5

What you actually need first of all is this script here:

#!/bin/sh
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";

#Code:
DISPLAY=:0 
notify-send "Hello James how is your day going"

You can test by running it every minute.

*/1 * * * * /tmp/myjob.sh

This will give you a popup every minute with how you are doing ;)

Ziazis
  • 2,184
1
crontab -u yourusername -e

Add example to turn off monitor in 2 minutes:

MAILTO=""
*/2 * * * * XAUTHORITY=/home/yourusername/.Xauthority DISPLAY=:0.0 xset dpms force off > /dev/null

restart cron

service cron restart

No need to create a .sh file!

Zanna
  • 72,312
neo76
  • 11
1

First, you should start bash scripts with 'shebang': #!/bin/bash (don't forget the # key). Also give the file execution permission:

chmod +x /tmp/myjob.sh 

Then on cron I would suggest you to put as:

0 15 * * * /tmp/myjob.sh

You cron job is set to run every day as 15:00 (3pm). I would suggest you to put it to run every 2 minutes to test first.

Adonist
  • 380