1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

script runs fine, just not as a cron job

Discussion in 'LOS Archive' started by Lucifer, 14 Nov 2002.

  1. Lucifer

    PermaBanned

    Joined: 17 Oct 2002

    Posts: 172

    Location: /dev/null

    i'm written a very simple bash script to run webalizer on my web logs, and it works fine. when i set up a cron job to run it every half hour however, it says the command cannot be found :confused:

    just running it:
    Code:
    [[email protected] root]# sh /home/stat-www.pl
    Webalizer V2.01-10 (Linux 2.4.18-3smp) English
    Using logfile /home/www/logs/access.log (clf)
    Creating output in current directory
    Hostname for reports is 'Gemini.ihateaol.co.uk'
    Reading history file... webalizer.hist
    Generating report for October 2002
    Generating report for November 2002
    Generating summary report
    Saving history information...
    11704 records in 0.71 seconds
    [[email protected] root]#
    
    but i get this email when it is run as a cron job:
    Code:
    From
    [email][email protected][/email] (Cron Daemon)
    To
    [email][email protected][/email]
    Date
    Thu, 14 Nov 2002 20:00:01 GMT
    Subject
    Cron <[email protected]> sh /home/stat-www.pl
    
    /home/stat-www.pl: webalizer: command not found
    
    any ideas?
     
  2. Shak

    PermaBanned

    Joined: 18 Oct 2002

    Posts: 2,010

    Location: Huddersfield / Antartica

    For some reason the script cant find webalizer when you are running the script, care to post the script?

    Shak
     
  3. Lucifer

    PermaBanned

    Joined: 17 Oct 2002

    Posts: 172

    Location: /dev/null

    all it is is:

    #!/bin/bash

    cd /home/www/html/misc/stat
    webalizer /home/www/logs/access.log

    has to change to the stat directory first cos thats where it generates the files when webalizer is run
     
  4. Ben

    Wise Guy

    Joined: 18 Oct 2002

    Posts: 2,328

    Location: Kent

    Probably the script doesn't run with the path to where webalizer is.

    try using the full path to it.

    need help finding it?
    do
    Code:
    whereis webalizer
    from a shell :)
     
  5. Lucifer

    PermaBanned

    Joined: 17 Oct 2002

    Posts: 172

    Location: /dev/null

    i perfer find / -name webalizer ;)

    also, running the cron job manually worked, and nothing had any trouble finding webalizer any other time. we'll see if this works in 25 mins anyway
     
  6. Lucifer

    PermaBanned

    Joined: 17 Oct 2002

    Posts: 172

    Location: /dev/null

    woohoo!
    *kisses ben

    now how do i stop it mailing me every half hour telling me it worked?
     
  7. Mpemba Effect

    Man of Honour

    Joined: 18 Oct 2002

    Posts: 7,097

    Yeah, you'll need to put in the full path of webalizer. With everything in cron you will need full paths. So something like:
    Code:
    #!/bin/bash
    
    cd /home/www/html/misc/stat
    /usr/bin/webalizer /home/www/logs/access.log
     
  8. Mpemba Effect

    Man of Honour

    Joined: 18 Oct 2002

    Posts: 7,097

    add
    Code:
    > /dev/null
    on the end of the crontab :)
     
  9. Ben

    Wise Guy

    Joined: 18 Oct 2002

    Posts: 2,328

    Location: Kent


    *steps away slowly* heh

    From the top of my crontab file (crontab -e)

    for example
    HTH :)


    EDIT: beaten to it by Mpemba Effect *sigh*
     
  10. How did you install it into cron? Pop the script into /etc/cron.hourly or into crontab -e?

    Im guessing its the first in which case it probs a cron config setting.... a quick look round /etc and I cant see anything obvious tho..
     
  11. Lucifer

    PermaBanned

    Joined: 17 Oct 2002

    Posts: 172

    Location: /dev/null

    sweet :D

    now for the super simple problem... the server clock is wrong, how can i set it and keep it synchronised?

    i added "server <time server IP>" to /etc/ntp.conf but i dunno what to do from there. RH 7.3
     
  12. Lucifer

    PermaBanned

    Joined: 17 Oct 2002

    Posts: 172

    Location: /dev/null

    crontab -e, cos i want it every 30 mins. fix0red now anyway thx :)
     
  13. Ben

    Wise Guy

    Joined: 18 Oct 2002

    Posts: 2,328

    Location: Kent

    If I were you i'd just add a cronjob that just runs
    /usr/sbin/ntpdate <server>

    e.g.
    /usr/sbin/ntpdate ntp.pipex.net

    :)
     
  14. Mpemba Effect

    Man of Honour

    Joined: 18 Oct 2002

    Posts: 7,097

    You must always use crontab -e to create edit crontabs. You should never edit the files directly.
     
  15. Shak

    PermaBanned

    Joined: 18 Oct 2002

    Posts: 2,010

    Location: Huddersfield / Antartica

    rdate is far more effective I find :p

    Code:
    rdate -u ntp2a.mcc.ac.uk
    
    Shak
     
  16. Lucifer

    PermaBanned

    Joined: 17 Oct 2002

    Posts: 172

    Location: /dev/null

    [[email protected] etc]# /usr/sbin/ntpdate ntp.demon.nl
    15 Nov 00:01:46 ntpdate[15656]: step time server 194.159.73.44 offset 3400.608745 sec

    haha :D you guys rock
    thanks a lot