Announcement

Collapse
No announcement yet.

<SOLVED> problem with bash script in KDE Task Scheduler

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

    <SOLVED> problem with bash script in KDE Task Scheduler

    SOLUTION (code only):
    Code:
    /home/tomc/.rvm/bin/rvm get latest > /home/tomc/rvm-update-log.txt
    /home/tomc/.rvm/bin/rvm reload
    exit
    yields:
    Code:
    05/01/11 04:30:01 PM	LDT	CRON[10898]	(tomc) CMD (/home/tomc/rvm-update.sh)
    05/01/11 04:30:07 PM	LDT	postfix/pickup[10896]	AB43220444: uid=1000 from=<tomc>
    05/01/11 04:30:07 PM	LDT	postfix/cleanup[6737]	AB43220444: message-id=<20110501223007.AB43220444@LDT>
    05/01/11 04:30:07 PM	LDT	postfix/qmgr[5016]	AB43220444: from=<tomc@LDT>, size=939, nrcpt=1 (queue active)
    05/01/11 04:30:07 PM	LDT	postfix/local[6739]	AB43220444: to=<tomc@LDT>, orig_to=<tomc>, relay=local, delay=0.11, delays=0.07/0/0/0.04, dsn=2.0.0, status=sent (delivered to mailbox)
    05/01/11 04:30:07 PM	LDT	postfix/qmgr[5016]	AB43220444: removed
    I have learned that cron has a very small path statement, and that's it's best to use fully specified paths.

    Now - what'a that "mailbox" referred to

    ----- (earlier posting -----

    I'm new to both Task Scheduler and Bash, and I'm somehow getting things wrong.

    What I want to do is have a script executed by cron twice a week to check for updates to my installed Ruby Version Manager. Here's my rvm-update.sh script -
    Code:
    #!/bin/sh
    # rvm-update.sh: updates Ruby Version Manager, when run by cron
    #
    # t. cloyd 2011.05.01
    ################################################
    echo date && BEGIN rvm update from rvm-update script
    rvm get latest > rvm-update-log.txt
    rvm reload
    echo date && END rem update
    exit
    ###### eof #####
    In the KDE Task Scheduler (obtained by installing the kde-config-cron package), I ask it to execute command /home/tomc/rvm-update.sh. The script was supposed to run at noon today, and it appears to have done just that. Using KSystemLog to look at the system log (I've never done ANY of this before, and it's rather fun!) I see these entries (in the midst of many others) which I interpret to mean that cron did its job:

    Code:
    05/01/11 12:00:02 PM	LDT	CRON[5054]	(tomc) CMD (/home/tomc/rvm-update.sh)
    05/01/11 12:00:02 PM	LDT	postfix/pickup[5017]	4315C1FF37: uid=1000 from=<tomc>
    05/01/11 12:00:02 PM	LDT	postfix/cleanup[5058]	4315C1FF37: message-id=<20110501180002.4315C1FF37@LDT>
    05/01/11 12:00:02 PM	LDT	postfix/qmgr[5016]	4315C1FF37: from=<tomc@LDT>, size=607, nrcpt=1 (queue active)
    05/01/11 12:00:02 PM	LDT	postfix/local[5060]	4315C1FF37: to=<tomc@LDT>, orig_to=<tomc>, relay=local, delay=0.32, delays=0.19/0.06/0/0.06, dsn=2.0.0, status=sent (delivered to mailbox)
    05/01/11 12:00:02 PM	LDT	postfix/qmgr[5016]	4315C1FF37: removed
    When I tested the script by asking Task Scheduler to run it manually, the script did exactly what it was supposed to: a terminal opened, and my first "echo" appeared, then output indicating a download from the rvm repository, then my second "echo" line appeared, and I was invited to press Enter to close things out. Checking my rvm-update-log.txt log file, I see the several pages of output which the rvm update always outputs.

    But the noon cron run didn't do any of this - no terminal screen, and my run log file, which had content, from last night's test runs, was wholly empty. I ran it manually again this afternoon, and it all worked. I set it to run every minutes via cron, and it does exactly what the noon run did - no log output, and now it's generating log errors (which I don't understand, and Google's not helping me, yet...):

    Code:
    05/01/11 04:13:01 PM	LDT	CRON[6768]	(tomc) CMD (/home/tomc/rvm-update.sh)
    05/01/11 04:13:01 PM	LDT	CRON[6767]	(CRON) error (grandchild #6768 failed with exit status 127)
    05/01/11 04:13:01 PM	LDT	postfix/pickup[6017]	2399220444: uid=1000 from=<tomc>
    05/01/11 04:13:01 PM	LDT	postfix/cleanup[6737]	2399220444: message-id=<20110501221301.2399220444@LDT>
    05/01/11 04:13:01 PM	LDT	postfix/qmgr[5016]	2399220444: from=<tomc@LDT>, size=663, nrcpt=1 (queue active)
    05/01/11 04:13:01 PM	LDT	postfix/local[6739]	2399220444: to=<tomc@LDT>, orig_to=<tomc>, relay=local, delay=0.1, delays=0.07/0/0/0.03, dsn=2.0.0, status=sent (delivered to mailbox)
    05/01/11 04:13:01 PM	LDT	postfix/qmgr[5016]	2399220444: removed
    Can anyone offer me any suggestions as to what's happening and how I can fix it? (and what's that mailbox referred to and how can I get to it)

    #2
    Re: &lt;SOLVED&gt; problem with bash script in KDE Task Scheduler

    Hello Tom,

    And the solution was....
    Thanks for sharing. I am facing the same frustrating issue.

    Johann

    Comment


      #3
      Re: &lt;SOLVED&gt; problem with bash script in KDE Task Scheduler

      Since you marked this SOLVED, I assume this is your only open question?:
      Originally posted by tomcloyd
      Now - what'a that "mailbox" referred to
      By default, cron will mail the output (if any) from the commands to the owner of the cron entry. The messages in your log are from your mail transfer agent (postfix), that reports mail sent to tomc@LDT.

      If you wish to change the default behavior you can give the MAILTO variable for cron, examples:
      MAILTO=mail.name@server.com
      (send output to address)
      MAILTO=
      (do not mail output)

      You can also modify the output mailing for individual cron entries by forwarding the output to (for example) /dev/null which will send the output to the bit heaven, examples of cron commands with output forwarding:
      /home/tomc/rvm-update.sh >> /dev/null
      (normal output [STDOUT] is not mailed, error output [STDERR] is mailed to MAILTO address)
      /home/tomc/rvm-update.sh >> /dev/null 2>&1
      (neither normal output nor error output is mailed)

      Of course you can use a file instead of /dev/null if you wish to "log" the output, forwarding with '>>' will append to the file, and '>' will rewrite the file (preserving only the latest output)

      If you want more information, googling for 'cron' and 'mailto' is probably a good start.

      Comment


        #4
        Re: &lt;SOLVED&gt; problem with bash script in KDE Task Scheduler

        Thank you for you attention to detail, in my post. My concerns are now fully addressed. Much appreciated!!!

        Comment

        Working...
        X