Results 1 to 5 of 5

Thread: crontab on hourly

  1. #1
    Join Date
    Nov 2010
    Beans
    4

    crontab on hourly

    hi

    i have this script that i want to run every hour, add the command in crontab but it not running. when i test the crontab to write something on the log file,it running.. When i try to run the script using commandline,it running.

    i hv go through the forum, and but still in the same.

    here the script :
    Code:
    #!/bin/bash
    #script change background desktop from Linux desktop hacks
    export DIR='/home/muhdazmilug/Pictures/Wallpaper/' #set directory for wallpaper
    export NUMBER=$RANDOM  #build in variable
    export TOTAL=0 # 
    #count the the total of file in dir
    for f in `ls $DIR`
    do
    let "TOTAL +=1"
    done
    let "NUMBER %=TOTAL" # select the image to be use
    export CURRENT=0
    for f in `ls $DIR`
    do
    if [ $CURRENT = $NUMBER ]
    then
    /usr/bin/gconftool-2 -t string -s /desktop/gnome/background/picture_filename $DIR/$f
    break
    fi
    let "CURRENT += 1"
    done
    i use sudo crontab -e to add the crontabs command

    Code:
    1 * * * * bash /home/muhdazmilug/changeWallpaper.sh
    1 * * * * echo "wallpaper Successful: $(date)" >> /tmp/crontabsLog.log
    thank in advance

  2. #2
    Join Date
    Feb 2005
    Location
    Melbourne, Australia
    Beans
    13,510
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: crontab on hourly

    Quote Originally Posted by muhdazmilug View Post
    hi

    i have this script that i want to run every hour, add the command in crontab but it not running. when i test the crontab to write something on the log file,it running.. When i try to run the script using commandline,it running.
    ........
    Code:
    1 * * * * bash /home/muhdazmilug/changeWallpaper.sh
    1 * * * * echo "wallpaper Successful: $(date)" >> /tmp/crontabsLog.log
    thank in advance
    Cron jobs do not run in your user Gnome environment, they run in their own system environment.

    Run the script from System-Preferences-Startup Applications.
    Regards, David.
    Please use the Forum search and Wiki search for immediate help
    Please mark your thread as Solved when appropriate
    New to technical forums?: How To Ask Questions The Smart Way

  3. #3
    Join Date
    Mar 2007
    Location
    Montreal Canada
    Beans
    14
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: crontab on hourly

    Quote Originally Posted by dcstar View Post
    Cron jobs do not run in your user Gnome environment, they run in their own system environment.

    Run the script from System-Preferences-Startup Applications.
    From root

    crontab -u user

    is supposed to allow creating a user crontab.

  4. #4
    Join Date
    Nov 2010
    Beans
    4

    Re: crontab on hourly

    when i sudo cat /var/log/syslog | grep CRON

    this appear..

    Code:
    Nov 22 23:44:01 muhdazmilugAspire3810T CRON[4202]: (root) CMD (   cd   /home/muhdazmilug/ScriptHelp/changeWallpaper.sh )
    Nov 22 23:44:01 muhdazmilugAspire3810T CRON[4200]: (CRON) error (grandchild #4202 failed with exit status 2)
    Nov 22 23:44:01 muhdazmilugAspire3810T CRON[4200]: (CRON) info (No MTA installed, discarding output)
    i search the exit status 2 say that Misuse of shell builtins..
    what Misuse of shell builtins mean?

  5. #5
    Join Date
    Nov 2010
    Beans
    4

    Re: crontab on hourly

    after searching in this forum,the problem had be solve...thank here

    here my new script look like..

    Code:
    #!/bin/bash
    
    # Get the pid of nautilus
    nautilus_pid=$(pgrep -u $LOGNAME -n nautilus)
    
    # If nautilus isn't running, just exit silently
    if [ -z "$nautilus_pid" ]; then
      exit 0
    fi
    
    # Grab the DBUS_SESSION_BUS_ADDRESS variable from nautilus's environment
    eval $(tr '\0' '\n' < /proc/$nautilus_pid/environ | grep '^DBUS_SESSION_BUS_ADDRESS=')
    
    # Check that we actually found it
    if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
      echo "Failed to find bus address" >&2
      exit 1
    fi
    
    # export it so that child processes will inherit it
    export DBUS_SESSION_BUS_ADDRESS
    
    
    export DIR='/home/muhdazmilug/Pictures/Wallpaper/' 
    export NUMBER=$RANDOM  #build in variable
    export TOTAL=0 # 
    for f in `ls $DIR`
    do
    let "TOTAL +=1"
    done
    let "NUMBER %=TOTAL" 
    export CURRENT=0
    for f in `ls $DIR`
    do
    if [ $CURRENT = $NUMBER ]
    then
    /usr/bin/gconftool-2 -t string -s /desktop/gnome/background/picture_filename $DIR/$f
    break
    fi
    let "CURRENT += 1"
    done
    exit

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •