[SOLVED] cron job stopped working after switching from Mint 14 to Mint 13
Linux MintThis forum is for the discussion of Linux Mint.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
cron job stopped working after switching from Mint 14 to Mint 13
Mint 13 Cinnamon 32 bit with Mint 16 backports
Kernel 3.2.0-23-generic
I used Mint 14 until support ended for it. Under Mint 14, I had a shell script that I ran with crontab to change my wallpaper (desktop background) every day at 07:00. It doesn't run under crontab on Mint 13 but the shell script works just fine every time I run it from the command line. It produces no output on the command line; after it runs, I just get my prompt back.
Here's the script:
Code:
#!/bin/bash
# Script to randomly set Background from files in a directory
# Directory Containing Pictures
DIR='/mnt/NTFS/Documents and Settings/All Users/Documents/My Pictures/Wallpaper'
# Command to Select a random jpg file from directory
# Delete the *.jpg to select any file but it may return a folder
PIC=$(ls "$DIR"/*.jpg | shuf -n1)
# Command to set Background Image
gsettings set org.gnome.desktop.background picture-uri file:"$PIC"
When I switched from Window$ to Linux, I just left most of my data in the Window$ NTFS partition.
Code:
$ ls -l wallpaper_changer.sh
-rwxr-xr-x 1 me me 522 Mar 3 2013 wallpaper_changer.sh
Here's my crontab file:
Code:
$ crontab -l
# 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)
#
# m h dom mon dow command
* 7 * * * /home/me/wallpaper_changer.sh
I have changed the last line to:
Code:
* * * * * /home/me/wallpaper_changer.sh
expecting the bash shell script to run every minute, but nothing happens. I've also tried
which I think should run the script every minute. The script still runs fine from the command line with the change you recommended, but the crontab job doesn't run.
I have no other crontab jobs scheduled, just wallpaper_changer.sh, which used to run under Mint 14 Cinnamon 32 bit.
$ cat wallpaper_changer.sh
#!/bin/bash
# Script to randomly set Background from files in a directory
# Directory Containing Pictures
DIR='/mnt/NTFS/Documents and Settings/All Users/Documents/My Pictures/Wallpaper'
# Command to Select a random jpg file from directory
# Delete the *.jpg to select any file but it may return a folder
# PIC=$(ls "$DIR"/*.jpg | shuf -n1)
PIC=$(ls "$DIR"/*.jpg | /usr/bin/shuf -n1)
# Command to set Background Image
#gconftool -t string -s /desktop/gnome/background/picture_filename "$PIC"
gsettings set org.gnome.desktop.background picture-uri file:"$PIC"
$
Still works fine from the command line but my background/wallpaper is not changing every minute like I think it should.
Although root is the owner of my NTFS partition, all directories and files are drwxrwxrwx or -rwxrwxrwx. I haven't changed anything in the Wallpaper directory since the script ran without problems in Mint 14.
Code:
$ ls -l /mnt/NTFS
.
.
.
drwxrwxrwx 1 root root 4096 Jan 9 2014 Documents and Settings
.
.
.
Code:
$ ls -l /mnt/NTFS/Documents\ and\ Settings/All\ Users/Documents/My\ Pictures/Wallpaper/
total 393867
.
.
.
-rwxrwxrwx 1 root root 946229 Jan 12 2012 typical_jpg_wallpaper.jpg
.
.
.
$ ls -l /usr/bin/gsettings
-rwxr-xr-x 1 root root 18032 Mar 28 2013 /usr/bin/gsettings
$ ls -l /usr/bin/X11/gsettings
-rwxr-xr-x 1 root root 18032 Mar 28 2013 /usr/bin/X11/gsettings
Code:
$ diff --report-identical-files /usr/bin/gsettings /usr/bin/X11/gsettings
Files /usr/bin/gsettings and /usr/bin/X11/gsettings are identical
Code:
$ cat wallpaper_changer.sh
#!/bin/bash
echo $PATH
# Script to randomly set Background from files in a directory
# Directory Containing Pictures
DIR='/mnt/NTFS/Documents and Settings/All Users/Documents/My Pictures/Wallpaper'
# Command to Select a random jpg file from directory
# Delete the *.jpg to select any file but it may return a folder
# PIC=$(ls "$DIR"/*.jpg | shuf -n1)
PIC=$(ls "$DIR"/*.jpg | /usr/bin/shuf -n1)
# Command to set Background Image
#gsettings set org.gnome.desktop.background picture-uri file:"$PIC"
/usr/bin/gsettings set org.gnome.desktop.background picture-uri file:"$PIC"
The crontab job doesn't run but the bash script still works fine from the command line, except that it doesn't echo my PATH env variable to the terminal. Strangely, it does echo my PATH variable to wpc.err.
$ cat wallpaper_changer.sh
#!/bin/bash
PATH=/home/me/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
# Script to randomly set Background from files in a directory
# Directory Containing Pictures
DIR='/mnt/NTFS/Documents and Settings/All Users/Documents/My Pictures/Wallpaper'
# Command to Select a random jpg file from directory
# Delete the *.jpg to select any file but it may return a folder
# PIC=$(ls "$DIR"/*.jpg | shuf -n1)
PIC=$(ls "$DIR"/*.jpg | /usr/bin/shuf -n1)
# Command to set Background Image
#gsettings set org.gnome.desktop.background picture-uri file:"$PIC"
/usr/bin/gsettings set org.gnome.desktop.background picture-uri file:"$PIC
nothing wrong with the script; crontab needs additional parameter
1. I don't want to use MATE. I've got nothing against it, but I started this thread to learn why my script stopped working, not to install another desktop environment that I'm not currently using.
2. There is no PPA vetting in Linuxland. While I'm sure that variety and Peter Levi are trustworthy, I don't see the need to add another PPA and install another program when I have a script that used to work just fine.
I found the solution to my problem by DuckDuckGo-ing the phrase:
Code:
Autolaunch error: X11 initialization failed
which appeared in my wpc.err file (see the "cat wpc.err" output above). Clearly something was wrong with accessing the X11 display manager. The solution is here: http://ubuntuforums.org/showthread.php?t=1023215 and requires specifying the DISPLAY env variable to crontab. Now my crontab looks like this:
$ cat wallpaper.sh
#!/bin/bash
# Script to randomly set Background from files in a directory
# Directory Containing Pictures
DIR='/mnt/NTFS/Documents and Settings/All Users/Documents/My Pictures/Wallpaper'
# Command to Select a random jpg file from directory
# Delete the *.jpg to select any file but it may return a folder
PIC=$(ls "$DIR"/*.jpg | shuf -n1)
# Command to set Background Image
gsettings set org.gnome.desktop.background picture-uri file:"$PIC"
So thanks for the considerable time you spent on this thread @Habitual. I hope this helps other people.
Last edited by Don_Nadie; 09-22-2014 at 05:36 AM.
Reason: slight crontab error
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.