Backgound
I am trying to run an sh
script every minute using crontab, but it is not working.
Problem
When I run the script manually, it executes properly, however crontab can't do it.
I created the job using crontab -e
, and I can see cron is running because if I type pgrep cron
I get the PID in return.
I also know that my time format is correct because I tested it with this online tester.
Code
wallpaperSlider.sh:
#!/bin/bash
feh --randomize --bg-fill /home/username/Pictures/wallpapers/*
crontab job:
SHELL=/bin/bash
* * * * * username /home/username/.crons/wallpaperSlider.sh
Research
I have read the most common errors in AskUbuntu and I don't think I am experiencing any.
I understand that perhaps I am missing some environment variable, but I am not sure how to check that.
I also know that crontab -e
changes/creates a tmp file, in my case /tmp/crontab.wCajAu/crontab
.
Question
- How can I make this script execute in cron?
- Having in mind that
crontab -e
changes a file in thetmp
folder, will I lose all changes once I reboot?
Best Answer
Your cron format is wrong. You want:
User's crontabs don't have a
username
field. That is only used for system-wide crontabs like/etc/crontab
. You also don't needSHELL=/bin/bash
since, even if your default shell isn't bash (it isdash
on Ubuntu), your script itself has the shebang line (#!/bin/bash
) so it will be run bybash
no matter what shell cron launches.You will probably have other issues as well though, since you're trying to run an application that communicates with the X server from cron. If so, you need to use: