LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint
User Name
Password
Linux Mint This forum is for the discussion of Linux Mint.

Notices


Reply
  Search this Thread
Old 09-07-2014, 12:18 PM   #1
Don_Nadie
Member
 
Registered: Aug 2009
Posts: 49

Rep: Reputation: 0
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

Code:
* * * * * /home/me/wallpaper_changer.sh >/dev/null 2>&1
but still, nothing happens.

This shouldn't be difficult so can someone help me? TIA.
 
Old 09-07-2014, 02:05 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Try using
Code:
/usr/bin/shuf
in the script.
 
Old 09-08-2014, 11:42 AM   #3
Don_Nadie
Member
 
Registered: Aug 2009
Posts: 49

Original Poster
Rep: Reputation: 0
not solved

Tnx 4 ur reply @Habitual, but my crontab job still doesn't run.

I assume you meant change the first line of my wallpaper_changer.sh script from

Code:
#!/bin/bash
to

Code:
#!/usr/bin/shuf
If you meant something else, please let me know.

The last line of my /var/spool/cron/crontabs/me/crontab file is currently

Code:
* * * * * /home/me/wallpaper_changer.sh >/dev/null 2>&1
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.
 
Old 09-08-2014, 12:21 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by Don_Nadie View Post
I assume you meant change the first line of my wallpaper_changer.sh script from

Code:
#!/bin/bash
to

Code:
#!/usr/bin/shuf
No I did not. sorry.
Change that back and use
Code:
PIC=$(ls "$DIR"/*.jpg | /usr/bin/shuf-n1)
instead of
Code:
PIC=$(ls "$DIR"/*.jpg | shuf -n1)
Let us know!
 
Old 09-11-2014, 04:46 AM   #5
Don_Nadie
Member
 
Registered: Aug 2009
Posts: 49

Original Poster
Rep: Reputation: 0
no joy

Code:
$ 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.

Thanks anyway.
 
Old 09-11-2014, 07:32 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
alter the cronjob just a bit using
Code:
* * * * * /home/me/wallpaper_changer.sh > /home/<you>/wpc.err
wait 1m and examine the /home<you>/wpc.err file for details

where <you> is your username on the system.
 
Old 09-12-2014, 01:07 PM   #7
Don_Nadie
Member
 
Registered: Aug 2009
Posts: 49

Original Poster
Rep: Reputation: 0
empty file

Last line of crontab file is now:

Code:
* * * * * /home/me/wallpaper_changer.sh > /home/me/wpc.err
which keeps producing an empty file every minute.

Code:
$ ls -l wpc.err
-rw-rw-r-- 1 me me 0 Sep 12 15:02 wpc.err
I would have expected this because running the script from the command line produces no output.
 
Old 09-12-2014, 05:31 PM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
and this is mounted with proper access permissions?
Code:
DIR='/mnt/NTFS/Documents and Settings/All Users/Documents/My Pictures/Wallpaper'
 
Old 09-13-2014, 12:40 PM   #9
Don_Nadie
Member
 
Registered: Aug 2009
Posts: 49

Original Poster
Rep: Reputation: 0
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
     .
     .
     .
 
Old 09-13-2014, 05:10 PM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Don:
I may have missed one, the /path/to/gsettings in
Code:
# Command to set Background Image
gsettings set org.gnome.desktop.background picture-uri file:"$PIC"
in ternminal >
Code:
whereis gsettings
and use that in the script.

You could also try echo'ing your $PATH into the top of the script under the shebang.

terminal >
Code:
echo $PATH
(example)
Code:
$ cat wallpaper_changer.sh
#!/bin/bash
PATH=/usr/local/bin:/usr/sbin:/usr/bin: #<-- output from echo $PATH

Last edited by Habitual; 09-13-2014 at 05:11 PM.
 
Old 09-15-2014, 01:12 PM   #11
Don_Nadie
Member
 
Registered: Aug 2009
Posts: 49

Original Poster
Rep: Reputation: 0
things are getting weird now

Code:
$ whereis gsettings
gsettings: /usr/bin/gsettings /usr/bin/X11/gsettings /usr/share/man/man1/gsettings.1.gz
Code:
$ 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"
Code:
$ crontab -l
    .
    .
    .
* * * * * /home/me/wallpaper_changer.sh > wpc.err
Code:
$ cat wpc.err
/usr/bin:/bin
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.
 
Old 09-15-2014, 02:41 PM   #12
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Don:
Sorry about that. I get going too fast:

in your script:
Code:
#!/bin/bash

echo $PATH
Open a terminal and issue a
Code:
echo $PATH
and use those results instead of echo $PATH in the same place.
Did this wallpaper_changer.sh script originate from http://community.linuxmint.com/tutorial/view/997 ?

Again, my apologies for my haste.
 
Old 09-18-2014, 08:10 AM   #13
Don_Nadie
Member
 
Registered: Aug 2009
Posts: 49

Original Poster
Rep: Reputation: 0
Code:
$ echo $PATH
/home/me/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Code:
$ 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
Code:
$ crontab -l
    .
    .
    .
* * * * * /home/me/wallpaper_changer.sh > wpc.err 2&>1
Code:
cat wpc.err
[sudo] password for me: 

** (process:24865): WARNING **: Command line `dbus-launch --autolaunch=ac63b47ceb21cada15b5f13f00000008 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n

** (process:24865): WARNING **: Command line `dbus-launch --autolaunch=ac63b47ceb21cada15b5f13f00000008 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n
I think I got the idea here: http://lifehacker.com/400505/rotate-...unds-in-ubuntu

So redirecting STDERR finally reveals something.

Thanks for all your help so far @Habitual and no need to apologize for anything.

Last edited by Don_Nadie; 09-21-2014 at 10:52 AM.
 
Old 09-19-2014, 08:35 AM   #14
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
http://community.linuxmint.com/tutorial/view/997 specifies using
Code:
mateconftool-2 -t string -s /desktop/mate/background/picture_filename $PIC
Have you, can you try that instead of
Code:
/usr/bin/gsettings set org.gnome.desktop.background picture-uri file:"$PIC
http://forums.linuxmint.com/viewtopi...f=219&t=162971 suggests the Variety .deb package.

Last edited by Habitual; 09-19-2014 at 08:54 AM.
 
Old 09-21-2014, 10:50 AM   #15
Don_Nadie
Member
 
Registered: Aug 2009
Posts: 49

Original Poster
Rep: Reputation: 0
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:
Code:
$ crontab -l
    .
    .
    .
0 7 * * * DISPLAY=:0.0 /home/me/wallpaper_changer.sh
and my original script now works again.

Code:
$ 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
 
  


Reply

Tags
cron, cronjob



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Mic stopped working on Linux Mint glacier.2000 Linux - Laptop and Netbook 19 06-27-2014 01:28 PM
[SOLVED] Sound stopped working on Mint 13, 64-bit w/Mate lordr0ke Linux - Hardware 5 02-11-2013 08:16 PM
scanner just stopped working with Linux Mint loshakova Linux - Newbie 64 04-18-2012 10:52 AM
Mint Update has stopped loading the notification icon at startup (Mint 10) icekool Linux Mint 6 12-19-2010 07:49 AM
cron job suddenly stopped working Gisli Linux - Software 1 08-25-2005 12:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint

All times are GMT -5. The time now is 05:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration