Announcement

Collapse
No announcement yet.

Script not running from crontab

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Script not running from crontab

    Hi All,

    I have created a sh script for an alaram purpose...

    Below is my script content

    home@home-localdomain:~/Documents/alaram$ pwd
    /home/home/Documents/alaram
    home@home-localdomain:~/Documents/alaram$ ls -l
    total 4912
    -rwxr-xr-x 1 home home 0 2011-10-05 00:28 alaram.log
    -rwxr-xr-x 1 home home 49 2011-10-05 00:44 alaram.sh
    -rwxr-xr-x 1 home home 5011584 2011-09-30 20:45 bg.mp3
    home@home-localdomain:~/Documents/alaram$ cat alaram.sh
    /usr/bin/vlc /home/home/Documents/alaram/bg.mp3

    The script is working fine when it been executed manually ... where as the same script is not running automatically from the crontab

    Below is my crontab entry for the same

    15 5 * * * /bin/sh /home/home/Documents/alaram/alaram.sh >>/home/home/Documents/alaram/alaram.log

    Please let me know if there is any specific file permission which need to grant to the script to make it run automatically from the crontab...

    Thanks

    #2
    Re: Script not running from crontab

    Code:
    /usr/bin/vlc /home/home/Documents/alaram/bg.mp3
    I suspect the reason is that vlc is a gui application. Your script is attempting to run it as root, and by default root cannot run gui's. Also it has no x screen to run it in.

    Maybe try aplay instead. Another problem you may run into is that pulseaudio is a user-based system, and may not work running as root without configuration. I think aplay bypasses pulse and works with alsa directly, so it's worth a try. Also mpg-321 might work.


    Edit: if that doesn't work, there is always kalarm, which runs as a user application from within kde, and will therefore work fine with pulse.
    We only have to look at ourselves to see how intelligent life might develop into something we wouldn't want to meet. -- Stephen Hawking

    Comment


      #3
      Re: Script not running from crontab

      Originally posted by doctordruidphd
      Your script is attempting to run it as root
      This is only true if it's root's crontab...a user crontab will run it as user.

      If it's a user crontab, my guess would be that the problem is that the $DISPLAY variable is not set (a GUI program like vlc needs to know the $DISPLAY (the X screen to run on). So I'd try the following:

      1. Modify your script to set the $DISPLAY:
      export DISPLAY=:0
      /usr/bin/vlc /home/home/Documents/alaram/bg.mp3
      (DISPLAY=:0 assumes you want to run vlc on the first X screen)

      2. To catch the (possible) errors in a log file, modify your crontab entry to output STDERR (not just STDOUT) to a file (in the example alaram.errors):
      15 5 * * * /bin/sh /home/home/Documents/alaram/alaram.sh >>/home/home/Documents/alaram/alaram.log 2>> /home/home/Documents/alaram/alaram.errors

      Comment


        #4
        Re: Script not running from crontab

        Scripts works perfectly from the crontab after exporting the display env variable with in the script...

        Thanks

        Comment

        Working...
        X