Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
not getting top output when cron runs script
Results 1 to 2 of 2

Thread: not getting top output when cron runs script

  1. #1

    not getting top output when cron runs script

    :? :cry:

    top output to file on cron plzz help
    I thought i had resolved the problem only to find the the script only works correctly if i run it manually.
    I entered it to run with a cron job to run every 5 minutes and it does run every 5 minutes. It also gives me part of the output i request but it will not give the "top" output. this is what i did for starters

    while in root i entered a cron job using
    crontab -e

    this is the entry:
    */5 * * * * /usr/local/bin/ht_stat.sh a > /dev/null

    This is the script i created:

    # This script has been giving uptime,date and httpd info every 5 minutes since sept. 01,'05.

    echo `date` >> /home/rau/htstat/htstat.txt

    uptime >> /home/rau/htstat/htstat.txt
    echo "HTTPD `ps -f | grep httpd | wc -l`" >> /home/rau/htstat/htstat.txt

    echo "" >> /home/rau/htstat/htstat.txt

    #I'm adding these 2 lines of code to get a top reading in the same intervals and put a line of space between the orginal reading and the top readings.

    [b]top -n 1 >> /home/rau/htstat/htstat.txt
    echo "" >> /home/rau/htstat/htstat.txt[/b]

    This is my output if the cron runs the job:

    Fri Sep 16 09:55:01 EDT 2005
    09:55:01 up 56 days, 21:31, 115 users, load average: 0.53, 0.48, 0.37
    HTTPD 2


    Fri Sep 16 10:00:00 EDT 2005
    10:00:00 up 56 days, 21:36, 115 users, load average: 0.38, 0.41, 0.36
    HTTPD 2


    Fri Sep 16 10:05:00 EDT 2005
    10:05:00 up 56 days, 21:41, 115 users, load average: 0.06, 0.22, 0.29
    HTTPD 2

    If i run the the job manually:

    ./ht_stat.sh

    I get the desired output like so:


    Fri Sep 16 10:25:35 EDT 2005
    10:25:35 up 56 days, 22:02, 115 users, load average: 0.18, 0.60, 0.58
    HTTPD 1
    top - 10:25:35 up 56 days, 22:02, 115 users, load average: 0.18, 0.60, 0.58
    Tasks: 163 total, 1 running, 162 sleeping, 0 stopped, 0 zombie
    Cpu(s): 3.8% us, 3.2% sy, 5.7% ni, 87.0% id, 0.2% wa, 0.0% hi, 0.0% si
    Mem: 516684k total, 469844k used, 46840k free, 169848k buffers
    Swap: 1052248k total, 65216k used, 987032k free, 90188k cached

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    10745 root 18 0 1984 892 1620 R 1.9 0.2 0:00.03 top
    1 root 16 0 2704 292 1316 S 0.0 0.1 0:03.31 init
    2 root 34 19 0 0 0 S 0.0 0.0 0:00.10 ksoftirqd/0
    3 root 5 -10 0 0 0 S 0.0 0.0 0:04.36 events/0
    4 root 5 -10 0 0 0 S 0.0 0.0 0:00.02 khelper
    5 root 13 -10 0 0 0 S 0.0 0.0 0:00.00 kacpid
    20 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 kblockd/0
    21 root 15 0 0 0 0 S 0.0 0.0 0:00.00 khubd
    33 root 15 0 0 0 0 S 0.0 0.0 0:27.96 pdflush
    35 root 7 -10 0 0 0 S 0.0 0.0 0:00.00 aio/0
    34 root 15 0 0 0 0 S 0.0 0.0 0:12.32 kswapd0

    184 root 15 0 0 0 0 S 0.0 0.0 0:07.93 kjournald
    668 root 15 0 0 0 0 S 0.0 0.0 0:00.00 kjournald
    669 root 15 0 0 0 0 S 0.0 0.0 0:00.30 kjournald
    670 root 15 0 0 0 0 S 0.0 0.0 0:00.19 kjournald
    671 root 15 0 0 0 0 S 0.0 0.0 0:05.28 kjournald
    672 root 15 0 0 0 0 S 0.0 0.0 0:09.25 kjournald
    1066 root 16 0 2568 572 1648 S 0.0 0.1 0:26.30 dhclient
    1097 root 16 0 3064 380 1296 S 0.0 0.1 0:04.09 syslogd
    1101 root 16 0 2500 252 1244 S 0.0 0.0 0:00.04 klogd
    1138 rpcuser 22 0 3252 272 1380 S 0.0 0.1 0:00.00 rpc.statd
    1163 root 16 0 2580 300 1296 S 0.0 0.1 0:01.60 rpc.idmapd
    1203 root 18 0 2252 268 1532 S 0.0 0.1 0:00.00 hcid
    1210 root 10 -10 0 0 0 S 0.0 0.0 0:00.00 krfcommd
    1229 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rpciod
    1230 root 21 0 0 0 0 S 0.0 0.0 0:00.00 lockd
    1235 root 17 0 8560 292 6704 S 0.0 0.1 0:00.00 mount.smbfs

    You have new mail in /var/spool/mail/root

    I just don't know why it works one way and not the other, somebody pleezz help me - caligal ops: :roll:

  2. #2
    Usually when cron tasks fail, but work from the command line it's because you either haven't specified a shell at the beginning of the script (no shebang #!), or haven't specified the full pathname to the executable files.

    Try this instead:

    Code:
    #!/bin/bash
    
    /bin/echo `date` >> /home/rau/htstat/htstat.txt 
    
    /usr/bin/uptime >> /home/rau/htstat/htstat.txt 
    
    /bin/echo "HTTPD `/bin/ps -f | /bin/grep httpd | /usr/bin/wc -l`" >> /home/rau/htstat/htstat.txt 
    
    /bin/echo "" >> /home/rau/htstat/htstat.txt 
    
    /usr/bin/top -n 1 >> /home/rau/htstat/htstat.txt 
    
    /bin/echo "" >> /home/rau/htstat/htstat.txt

    The #!/bin/bash will run your bash scripts beforehand so your regular PATH statements will be set, so you may not have to give the full path names for the executables. I did both to increase the length of the post or something .

Similar Threads

  1. mplayer runs as root, but not as user
    By S_D_Willie in forum Linux - General Topics
    Replies: 12
    Last Post: 10-04-2002, 07:52 PM
  2. Chromium Runs Slow. Need to change Vendor Name...
    By Aaron_Adams in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 07-18-2002, 09:30 AM
  3. Every computer runs Windows
    By Ashcrow in forum General Chat
    Replies: 2
    Last Post: 05-12-2002, 04:35 AM
  4. XMMS only runs for root
    By FORTRAN_gy in forum Linux - Software, Applications & Programming
    Replies: 5
    Last Post: 04-11-2002, 06:02 PM
  5. MS Office runs on Linux now
    By stryder144 in forum General Chat
    Replies: 4
    Last Post: 03-28-2002, 09:02 PM

Bookmarks

Posting Permissions

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