Announcement

Collapse
No announcement yet.

CRON script issues

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

    CRON script issues

    Hi,

    I'm not actually new to linux but posting in here as I'm pretty sure the fix to this will be simple plus i'm really out of practice! ;P

    Searched all over forums & google and just can't seem to fix my problem with the information i've collected :/

    Basically I have a script, kept in /usr/sbin/ called force-standby, goes a little something like this;

    Code:
    #!/bin/bash
    xset dpms force standby
    echo "logging!" >> /tmp/fslogs.log
    I have a "monitoring screen" so all staff can view events popping up in zabbix - on this box I'm running caffeine so the monitor doesn't sleep during the day, and use this script to make the monitor sleep when we leave the office.

    The script runs OK if you run it from the box, under both root and the one other user account, as you can see ive set up a basic log to tell me each time the script runs.

    However cron just wont run it, I've stuck it in /etc/crontab - perhaps this is the wrong file to be editing for kubuntu i'm not sure, this is how it reads;

    Code:
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    # m h dom mon dow user command
    17 *  * * *  root  cd / && run-parts --report /etc/cron.hourly
    25 6  * * *  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6  * * 7  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    52 6  1 * *  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
    32 10  * * *  root  /usr/sbin/force-standby
    #
    And this is the response I get from cron in /var/log/syslog;

    Code:
    Apr 19 07:53:33 monitor rsyslogd: [origin software="rsyslogd" swVersion="4.2.0" x-pid="805" x-info="[url]http://www.rsyslog.com"][/url] rsyslogd was HUPed, type '$
    Apr 19 07:53:33 monitor anacron[18305]: Job `cron.daily' terminated
    Apr 19 07:53:33 monitor anacron[18305]: Normal exit (1 job run)
    Apr 19 08:17:01 monitor CRON[19047]: (root) CMD (  cd / && run-parts --report /etc/cron.hourly)
    Apr 19 09:17:01 monitor CRON[19840]: (root) CMD (  cd / && run-parts --report /etc/cron.hourly)
    Apr 19 10:17:01 monitor CRON[20693]: (root) CMD (  cd / && run-parts --report /etc/cron.hourly)
    Apr 19 10:29:00 monitor init: cron main process (7280) killed by TERM signal
    Apr 19 10:29:00 monitor cron[20962]: (CRON) INFO (pidfile fd = 3)
    Apr 19 10:29:00 monitor cron[20963]: (CRON) STARTUP (fork ok)
    Apr 19 10:29:00 monitor cron[20963]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
    Apr 19 10:32:01 monitor CRON[21009]: (root) CMD (^I/usr/sbin/force-standby)
    Apr 19 11:17:01 monitor CRON[21699]: (root) CMD (  cd / && run-parts --report /etc/cron.hourly)
    Cron just refuses to run the script, i've tried it in user crontab, and also tried changing roots crontab to a different user and removing any user at all, I've also tried removing the path but still nothing :/

    Can anyone help?

    Thanks!

    #2
    Re: CRON script issues

    Try this -

    32 10 * * * root sh /usr/sbin/force-standby

    You're running a shell script - you've gotta call the shell
    we see things not as they are, but as we are.
    -- anais nin

    Comment


      #3
      Re: CRON script issues

      ahhh, still same result! should cron still need prompting to call SH if the script calls it anyway?

      thanks anyway though!

      Comment


        #4
        Re: CRON script issues

        Stupid question here. Is the script set as executable?
        we see things not as they are, but as we are.
        -- anais nin

        Comment


          #5
          Re: CRON script issues

          Hehe, yeah it is, all perms etc fine too

          As mentioned, it runs as expected for both root & standard user outside of cron

          Comment


            #6
            Re: CRON script issues

            Originally posted by moo
            However cron just wont run it, I've stuck it in /etc/crontab - perhaps this is the wrong file to be editing for kubuntu i'm not sure, this is how it reads;
            Putting the cron command line in a separate file in /etc/cron.d/ might be better if there are updates to the /etc/crontab, but otherwise /etc/crontab should be fine in kubuntu as well.

            My first thought would be that the script runs as reported by your cron log (the fact that there is a "^I" in front of the command to run suggests that you have both space(s) and a tab char between "root" and "/usr/sbin/force-standby", but that probably won't cause problems).

            However, I'd suggest you let cron log the output of the script to see if there are errors running xset via cron (the environment is likely not the same as when running the command manually), you might need to set the $DISPLAY variable for the xset command, for example.

            you can log the output to your log file by using this in your cron:
            32 10 * * * root /usr/sbin/force-standby >> /tmp/fslogs.log 2>&1
            and check /tmp/fslogs.log for errors once the script runs

            Comment


              #7
              Re: CRON script issues

              Nice one Kubicle! Thanks for that advice, will check out the logs today & also see if that display variable makes a difference

              Will report back soon as!

              Cheeers!

              Comment

              Working...
              X