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
  •  


Apple MacBook Air 13.6” M2 8GB 256GB SSD 2022 MLY33LL/A 8‑Core CPU 8‑Core GPU picture

Apple MacBook Air 13.6” M2 8GB 256GB SSD 2022 MLY33LL/A 8‑Core CPU 8‑Core GPU

$529.95



8-core 10-core GPU baseboard 8654 to PCIE 5.0x16 GPU expansion baseboard picture

8-core 10-core GPU baseboard 8654 to PCIE 5.0x16 GPU expansion baseboard

$377.77



Dell Alienware m15 R7 AMD Ryzen 7 6800H 16GB DDR5 1TB SSD RTX 3070 Ti WIN 11 PRO picture

Dell Alienware m15 R7 AMD Ryzen 7 6800H 16GB DDR5 1TB SSD RTX 3070 Ti WIN 11 PRO

$920.00



Panasonic Toughbook CF19 MK8 Core i5 3610ME 2.7GHz 12GB RAM 512GB SSD Win 10 Pro picture

Panasonic Toughbook CF19 MK8 Core i5 3610ME 2.7GHz 12GB RAM 512GB SSD Win 10 Pro

$319.00



HP - OmniBook 3 16

HP - OmniBook 3 16" 2K Touchscreen Laptop - Intel Core Ultra 5 (2025) - 8GB M...

$479.99



(New) AMD Ryzen 7 5700X 8 Core 16 Thread AM4 Unlocked 3.4 GHz CPU OEM Tray picture

(New) AMD Ryzen 7 5700X 8 Core 16 Thread AM4 Unlocked 3.4 GHz CPU OEM Tray

$169.99



Lenovo LOQ 15 15.6

Lenovo LOQ 15 15.6" FHD 144Hz 8-Core i5-12450HX 16GB 512GB SSD GeForce RTX 4050

$799.00



Dell - XPS 13.4

Dell - XPS 13.4" 3K Touchscreen Laptop - Intel Core 5 Series 3 320 2026 - 8GB...

$699.99



Lenovo ThinkPad T480 Core i5-8250u 1.6GHz 8GB 256GB SSD 14

Lenovo ThinkPad T480 Core i5-8250u 1.6GHz 8GB 256GB SSD 14" ***Boot to Bios

$110.00



ACER ASPIRE 5 A515-56-50RS CORE i5 1135G7 / 2.4 GHz Windows 11 8 GB RAM picture

ACER ASPIRE 5 A515-56-50RS CORE i5 1135G7 / 2.4 GHz Windows 11 8 GB RAM

$294.99