Results 1 to 9 of 9

Thread: Trying to debug a cron job

  1. #1
    Senior Member registered user
    Join Date
    Nov 2003
    Posts
    203

    Trying to debug a cron job

    Running knoppix 4.02 cd. Cron job seems to kick off as indicated by cdrom and hd activity lights but no evidence that the app ran. Is there some log somewhere where I can check what cron did?

  2. #2
    Senior Member registered user
    Join Date
    Dec 2003
    Location
    Salt Lake City, UT, U.S.A.
    Posts
    1,338
    turbine,

    Ahhh, the no output isnt a good thing... thing... hehehe

    Here's what I did... tho this is on a Hard Drive Installed Kanotix, I am quite sure that cron, is cron, is cron, as long as its cron, kind of thing...

    Add the following to the beginning of crontab -e ...

    root@neo:~# crontab -l
    # m h dom mon dow command
    MAILTO=root
    #

    Note the MAILTO line - this, of course is the roots crontab...

    This should force cron to send you mail, either sendmail or exim4 stuff, of the complete output of that cron job... it should be noted, you may get more output, from the daily, weekly, monthly, hourly cron tasks by editting those crontabs as well, same command - MAILTO=[whichuser]

    It should also be noted, and was pointed out to me, that having root mail is not safe, nor secure, the correct way, is, to have that root mail forwarded to a normal users mail, that can be accomplished by adding the following at the end of the /etc/aliases file: root: [whichuser] -=- that way, any mail sent to root, will get passed over to a normal user, of your choice...

    Hope this helps,
    MS Cuddles
    -=- Come to the Dark Side, we have penguins -=-

  3. #3
    Senior Member registered user
    Join Date
    Nov 2003
    Posts
    203
    Thank you very much, Cuddles, I really appreciate your help. I must be in way over my head, though, because I understood very little of what you told me.

    I have a cron job that I set up on my hd install of Debian Sarge and it runs just fine. As with this job I set it up using Kcron rather than fiddling with manual editing of files. The particular job, though, was different on Sarge.

    The batch file that I'm trying to run on Knoppix 4.02 is just a simple procedure to update my clock
    from the contents of a web page, here it is:

    ************************************************** ******

    #!/bin/bash
    cd /home/knoppix/tmp
    wget http://tycho.usno.navy.mil/cgi-bin/timer.pl -O time.txt
    timedataline=`grep EST time.txt`
    thehour=`echo $timedataline | cut -c 14,15`
    if [ `echo $timedataline | grep -c PM` -gt 0 ]
    then
    let thehour=thehour+12
    fi
    theminute=`echo $timedataline | cut -c 16,17,18`
    theseconds=`echo $timedataline | cut -c 19,20,21`
    sudo date -s $thehour$theminute$theseconds
    rm -f time.txt
    date >> /home/knoppix/Desktop/date.log
    *************************************************

    Looking at your explanation, I guess the first thing is I don't know what crontab -e is.

    Kcron placed the following file called "knoppix" into the /var/spool/cron/crontabs directory:

    ************************************************** *********
    # DO NOT EDIT THIS FILE - edit the master and reinstall.
    # (/ramdisk/tmp/kde-knoppix/kcron0Z5Vea.tmp installed on Wed Nov 15 06:07:08 2006)
    # (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
    #
    0 8 * * * /ramdisk/home/knoppix/Desktop/settimefromnet
    # This file was written by KCron. Copyright (c) 1999, Gary Meyer
    # Although KCron supports most crontab formats, use care when editing.
    # Note: Lines beginning with "#\" indicates a disabled task.

    ************************************************** *********

    Incidentally, Kcron has a menu item that allows you to test run your job. When I click
    that, the job runs fine.

  4. #4
    Senior Member registered user
    Join Date
    Dec 2003
    Location
    Salt Lake City, UT, U.S.A.
    Posts
    1,338
    turbine,

    ok, crontab -e is run on a konsole, depending on the user, it runs as the users konsole... KCron is a gui front-end to saving crontab files, used by cron... see the data in your crontab output above, "crontab version:..."

    If you prefer to use KCron over the underlying, thats ok, this is kind of like the synaptic / apt issue... synaptic is like KCron, and apt is like crontab -e and crontab -l commands... no biggy here...

    You want to add

    MAILTO=YourUserNameHere

    and put it before your cron job, it should be the first line you can place in the file... i.e.

    MAILTO=cuddles
    # Run this job every tuesday at 8:00 AM
    0 8 ...
    # Run this job ....
    ...

    again, all this does is send all cronjobs that display any output to a screen - if they are run from a command line - to a file, and that file output is then sent to the "user" you supplied on the MAILTO line...

    if you want to forward that mail, you edit the /etc/aliases file and point the user to another user, but, you dont have to... I get a lot of root mail, from jobs I run in cron, as root... and even though I keep a root konsole open most of the time, I'd prefer to read the root mail as a regular user, me, so I forward the root mail to my personal user account, cuddles... But to get the mail from a cronjob, the aliases thing is not needed, just the MAILTO

    Ok?
    MS Cuddles
    -=- VISTA - def: The Titanic of Microsoft -=-

  5. #5
    Senior Member registered user
    Join Date
    Nov 2003
    Posts
    203
    Ok, thanks to your patience the fog is starting to lift.

    Since the only user that I have on knoppix is knoppix itself, you want me to
    insert the line

    MAILTO=knoppix

    into the file called "knoppix" in the /var/spool/cron/crontabs directory

    even though it tells me not to edit that file, I assume(dangerous) that's ok.

    So then, after the next time that cron attempts to run my job, would I open
    a root console and issue readmail? Or, since I told it to mail to knoppix
    can I just open a regular console and read the mail?

    Thanks again, Cuddles.

  6. #6
    Senior Member registered user
    Join Date
    Dec 2003
    Location
    Salt Lake City, UT, U.S.A.
    Posts
    1,338
    turbine,

    By george, I think you've got it!

    Even though the crontab file says not to edit the file, my guess is, that, that warning is so that you dont mess up being able to use KCron to edit it in the future, you may want to check this, as, I have manually editted my crontabs, using a simple editor, and then used "crontab -e" to verify nothing has gone wrong, just in case.

    If you only have one user, that being the default user, I would say, you just need to open a konsole, and what I do is, issue a "mail" command. If I have mail, it will display the list of mail that user has, if no mail exists, it just displays "no mail" and returns to a prompt. Its a ritual I go through every morning, I have at least six cron jobs that run over the night, and so, I check how they ran, every morning. I have on "heavy" nights, as many as 10 to 15 mails to check...

    The only problem I have found with that MAILTO command, is, that, its an ALL or NOTHING kind of thing... In other words, you either get everything mailed to you, or nothing at all. If the cronjob displays even one single character, you will get a mail message of it, rather a PITA sometimes, so, when you get a script working, you may tailor down your display information, so that the mail message is more informative, but, not extremely verbose.

    What I tend to do, is, as a creation of a script happens, I go over-board with echo statements to ensure the script is setting what it should, testing what it should, and doing all that I wanted it to, then, when I am satisfied, I start taking out the "testing" echo's, and changing the output of what I do display, for more of a "user" output. In many cases, I dedicate a "log" file for its output, and port the echo's to that file, instead of the screen. That way, the mail log file I have to read is easier to follow, as what it was doing, and any output of values, checks, etc... can be viewed, if something wasnt working right in the log mail file, by using the file, but thats me...

    Well, hopefully, you have a handle on that option in your crontab, and if your mail starts to get "boring" and you dont need to keep checking it on a daily basis anymore, you can just put a # in front of it, and disable the whole shebang,

    MS Cuddles,
    -=- Come to the Dark Side, we have penguins -=-

  7. #7
    Senior Member registered user
    Join Date
    Nov 2003
    Posts
    203
    Well, I put in my MAILTO, and I put in echo statements, but still nothing. Seems that cron just isn't running the job. Something happens, though because at the alotted time for the job to run you can see activity on the computer, such as cdrom activity. But no mail messages are sent to either knoppix or root and no setting of the clock. Nothing. I'm baffled.

  8. #8
    Senior Member registered user
    Join Date
    Dec 2003
    Location
    Salt Lake City, UT, U.S.A.
    Posts
    1,338
    try this little script, I call it 'adjusttime', for me, it runs every night at 23:55 hours...

    root@morpheus:~# cat /usr/local/bin/adjusttime
    #!/bin/bash
    #
    # This is a SEQUENCIAL subnit script, for multi-systems...
    # i.e. this script (submit) (chained)
    # -----------
    # \----------> another script (local or remote)
    # \----------> another script (local or remote)
    # \----------> another script (local or remote)
    #
    # When system is neo - it submits to local, then remote systems, this same script...
    # When run from another system, not neo, just runs the script locally
    #
    # ensure we are root...
    if [ $(id -u) != 0 ]; then
    echo Error: You must be root to run this script!
    exit 1
    fi
    SCRIPTNAME="adjusttime"
    #
    BYPASSBANNER=""
    if [ "$1" == "bypass" ]; then
    shift 1
    BYPASSBANNER="YES"
    fi
    #
    CommonAuditCall () {
    /usr/local/bin/audittrail "$SCRIPTNAME * $@"
    }
    #
    ErrorRoutine () {
    # if we have an error during ntpdate... we come here, then exit...
    CommonAuditCall "ABORT ntpdate error"
    exit 1
    }
    #
    CommonAuditCall "START '$@'"
    #
    WHATSYSTEMAREWE="$(hostname)"
    #
    # FLAGS...
    # SKIP PROCESSING OF THIS SYSTEM Flags...
    SKIPNEO=""
    SKIPMORPHEUS=""
    SKIPTRINITY="YES"
    #
    case "$WHATSYSTEMAREWE" in
    neo)
    # looks good, we are running on neo, lets proceed through...
    ;;
    *)
    if [ "$BYPASSBANNER" = "" ]; then
    echo " ************************************************** ******************"
    echo "* Any errors you are not sure about, please notify your System Admin *"
    echo " ************************************************** ******************"
    fi
    ;;
    esac
    #
    # NTPSERVERADDY="ntp1.cs.wisc.edu"
    NTPSERVERADDY="time-a.nist.gov time-b.nist.gov"
    case "$WHATSYSTEMAREWE" in
    neo)
    # Continue processing... we are on the "server" side... (submit to other systems)
    # Process neo... (local)
    if [ "$SKIPNEO" = "" ]; then
    CommonAuditCall "SUBMIT to 'local'"
    echo "Starting Atomic Clock Time Update (adjusttime) on $WHATSYSTEMAREWE"
    echo " -- Current time... $(date +%m/%d/%Y) @ $(date +%T)"
    echo " ---- Getting ntp time from server '$NTPSERVERADDY'..."
    echo " ------ *** three passes of five attempts will be made... ***"
    echo " -- *** Pass 1 ***"
    PASS1STIME="$(date +%T)"
    /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || ErrorRoutine
    PASS1ETIME="$(date +%T)"
    echo " -- Was: $PASS1STIME ... Is: $PASS1ETIME"
    sleep 2
    echo " -- *** Pass 2 ***"
    PASS2STIME="$(date +%T)"
    /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || ErrorRoutine
    PASS2ETIME="$(date +%T)"
    echo " -- Was: $PASS2STIME ... Is: $PASS2ETIME"
    sleep 2
    echo " -- *** Pass 3 ***"
    PASS3STIME="$(date +%T)"
    /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || ErrorRoutine
    PASS3ETIME="$(date +%T)"
    echo " -- Was: $PASS3STIME ... Is: $PASS3ETIME"
    echo " -- New time... $(date +%m/%d/%Y) @ $(date +%T)"
    echo
    echo " -- Hardware clock is:"
    /sbin/hwclock --show
    echo " -- Setting Hardware clock to current system clock"
    /sbin/hwclock --systohc
    echo " -- Hardware clock is now:"
    /sbin/hwclock --show
    echo "Completed (adjusttime) @ $(date +%m/%d/%Y) @ $(date +%T) on $WHATSYSTEMAREWE [eof]"
    fi
    # Process morpheus...
    if [ "$SKIPMORPHEUS" = "" ]; then
    echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
    # submit the process over to remote system...
    CommonAuditCall "SUBMIT to 'morpheus'"
    ssh morpheus /usr/local/bin/adjusttime bypass $@
    fi
    # Process trinity...
    if [ "$SKIPTRINITY" = "" ]; then
    echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
    # submit the process over to remote system...
    CommonAuditCall "SUBMIT to 'trinity'"
    ssh trinity /usr/local/bin/adjusttime bypass $@
    fi
    ;;
    morpheus)
    # Process morpheus... (as local - either called, or manually run locally)
    if [ "$SKIPMORPHEUS" = "" ]; then
    echo "Starting Atomic Clock Time Update (adjusttime) on $WHATSYSTEMAREWE"
    echo " -- Current time... $(date +%m/%d/%Y) @ $(date +%T)"
    echo " ---- Getting ntp time from server '$NTPSERVERADDY'..."
    echo " ------ *** three passes of five attempts will be made... ***"
    echo " -- *** Pass 1 ***"
    PASS1STIME="$(date +%T)"
    /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || ErrorRoutine
    PASS1ETIME="$(date +%T)"
    echo " -- Was: $PASS1STIME ... Is: $PASS1ETIME"
    sleep 2
    echo " -- *** Pass 2 ***"
    PASS2STIME="$(date +%T)"
    /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || ErrorRoutine
    PASS2ETIME="$(date +%T)"
    echo " -- Was: $PASS2STIME ... Is: $PASS2ETIME"
    sleep 2
    echo " -- *** Pass 3 ***"
    PASS3STIME="$(date +%T)"
    /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || ErrorRoutine
    PASS3ETIME="$(date +%T)"
    echo " -- Was: $PASS3STIME ... Is: $PASS3ETIME"
    echo " -- New time... $(date +%m/%d/%Y) @ $(date +%T)"
    echo
    echo " -- Hardware clock is:"
    /sbin/hwclock --show
    echo " -- Setting Hardware clock to current system clock"
    /sbin/hwclock --systohc
    echo " -- Hardware clock is now:"
    /sbin/hwclock --show
    echo "Completed (adjusttime) @ $(date +%m/%d/%Y) @ $(date +%T) on $WHATSYSTEMAREWE [eof]"
    fi
    ;;
    trinity)
    # Process trinity... (as local - either called, or manually run locally)
    if [ "$SKIPTRINITY" = "" ]; then
    echo "Starting Atomic Clock Time Update (adjusttime) on $WHATSYSTEMAREWE"
    echo " -- Current time... $(date +%m/%d/%Y) @ $(date +%T)"
    echo " ---- Getting ntp time from server '$NTPSERVERADDY'..."
    echo " ------ *** three passes of five attempts will be made... ***"
    echo " -- *** Pass 1 ***"
    PASS1STIME="$(date +%T)"
    /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || ErrorRoutine
    PASS1ETIME="$(date +%T)"
    echo " -- Was: $PASS1STIME ... Is: $PASS1ETIME"
    sleep 2
    echo " -- *** Pass 2 ***"
    PASS2STIME="$(date +%T)"
    /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || ErrorRoutine
    PASS2ETIME="$(date +%T)"
    echo " -- Was: $PASS2STIME ... Is: $PASS2ETIME"
    sleep 2
    echo " -- *** Pass 3 ***"
    PASS3STIME="$(date +%T)"
    /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || /usr/sbin/ntpdate $NTPSERVERADDY || ErrorRoutine
    PASS3ETIME="$(date +%T)"
    echo " -- Was: $PASS3STIME ... Is: $PASS3ETIME"
    echo " -- New time... $(date +%m/%d/%Y) @ $(date +%T)"
    echo
    echo " -- Hardware clock is:"
    /sbin/hwclock --show
    echo " -- Setting Hardware clock to current system clock"
    /sbin/hwclock --systohc
    echo " -- Hardware clock is now:"
    /sbin/hwclock --show
    echo "Completed (adjusttime) @ $(date +%m/%d/%Y) @ $(date +%T) on $WHATSYSTEMAREWE [eof]"
    fi
    ;;
    *)
    echo "System name is not in script! ABORT!"
    CommonAuditCall "ABORT invalid system calling script"
    exit 1
    ;;
    esac
    CommonAuditCall "END"
    exit 0
    root@morpheus:~#


    I know, it is rather lengthly, but, you may look at the "ntpdate" command, I use it within the above script... This script is also a little long because it not only gets the time in three passes ( an attempt to average the time adjustment ), but, also tries to get it each of the three times, up to five chances... ( just in case )

    In addition, the script is designed to ssh over to all known systems within our internal network, and do the same thing on each of them... That way, one cron job, submits and tracks log file for all systems...

    I have found that ntpdate to work almost flawlessly on adjusting the time on the "currently" two systems we have running atm...

    Hope this helps,
    MS Cuddles

  9. #9
    Senior Member registered user
    Join Date
    Nov 2003
    Posts
    203
    Mistery solved, sorta. I was running from my knoppix 4.02 dvd. I rebooted with my knoppix 4.02 cd, setup the cron job, and it works. Must have a bad burn on the dvd. Gotta find that command to do a md5sum check on all of the files. Thanks again Cuddles.

Similar Threads

  1. Need Knoppix Guru to Help Debug Hardware Problem
    By Little Mac in forum Hardware & Booting
    Replies: 2
    Last Post: 09-15-2006, 07:13 PM
  2. Cron
    By rrijkse in forum Customising & Remastering
    Replies: 2
    Last Post: 07-28-2004, 05:43 AM
  3. debug output
    By cYmen in forum Hardware & Booting
    Replies: 0
    Last Post: 06-05-2003, 10:56 PM
  4. cron
    By punk000 in forum General Support
    Replies: 1
    Last Post: 02-24-2003, 07:21 PM
  5. unknown cron job
    By tegan in forum General Support
    Replies: 2
    Last Post: 02-01-2003, 01:51 AM

Posting Permissions

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


USB 3.0 Flash Drive 32GB 64GB 128GB Memory Stick Thumb Stick Lot Pack picture

USB 3.0 Flash Drive 32GB 64GB 128GB Memory Stick Thumb Stick Lot Pack

$826.09



SanDisk Ultra Luxe USB 3.1 Flash Drive – 5 Pack | Premium Metal USB Flash Drives picture

SanDisk Ultra Luxe USB 3.1 Flash Drive – 5 Pack | Premium Metal USB Flash Drives

$59.99



Microsoft Windows 11 Pro 64bit - New Sealed – Flash USB 1 PC picture

Microsoft Windows 11 Pro 64bit - New Sealed – Flash USB 1 PC

$49.99



Windows 11 Pro Install/Recovery/Repair USB Flash Drive picture

Windows 11 Pro Install/Recovery/Repair USB Flash Drive

$35.00



Sandisk 16GB 32GB 64GB 128GB Cruzer Blade Flash Drive Memory Stick USB Lot Pack picture

Sandisk 16GB 32GB 64GB 128GB Cruzer Blade Flash Drive Memory Stick USB Lot Pack

$175.90



Sandisk Flash Drive 16GB 32GB 64GB 128GB 256GB 512GB Blade Glide Ultra Flair lot picture

Sandisk Flash Drive 16GB 32GB 64GB 128GB 256GB 512GB Blade Glide Ultra Flair lot

$623.38



Kingston 32GB 64GB 128GB 256GB USB 3.0 Flash Drive Thumb Memory Stick Pen lot picture

Kingston 32GB 64GB 128GB 256GB USB 3.0 Flash Drive Thumb Memory Stick Pen lot

$135.90



LOT 10x SanDisk 32GB ULTRA USB 3.0 flash drive SDCZ48-032G 32 GB read 100 MB/s picture

LOT 10x SanDisk 32GB ULTRA USB 3.0 flash drive SDCZ48-032G 32 GB read 100 MB/s

$39.80



Wholesale 5/10/100PCS 1GB 2GB 4GB 8GB 16GB 32GB USB 2.0 Flash Drive Memory Stick picture

Wholesale 5/10/100PCS 1GB 2GB 4GB 8GB 16GB 32GB USB 2.0 Flash Drive Memory Stick

$378.00



Tesla 128gb usb flash drive 3.1 picture

Tesla 128gb usb flash drive 3.1

$15.99