Linux shell script is not working ...

Discussion in 'Site & Server Administration' started by ohcnetwork, Dec 30, 2005.

  1. #1
    I set up the following shell script for a debugging purpose:

    1. ssh into the server.
    2. Go to /home/admin
    3. mkdir cron
    4. cd cron
    5. vi checkapache.sh
    6. Type the following code.
     
    #!/bin/bash
    mn=`date +%M`
    if [ $mn -eq 0 ]; then
    mn=`date`
    echo $mn
    fi
    CNT=`ps ax | grep -v grep | grep -c httpd`
    echo $CNT
    if [ $CNT -gt 99 ]; then
    CNT=0
    fi
    if [ $CNT -le 11 ]; then
    mn=`date`
    echo $mn '- WARNING httpd needs to be restarted'
    fi
    
    Code (markup):
    7. chmod 755 checkapache.sh
    8. Plesk -> server -> crontab -> add new task

    Minute: */5
    Hour: *
    Day of month: *
    Month: *
    Day of week: *
    Command: /home/admin/cron/checkapache.sh>>/home/admin/cron/log

    I expected that the script would write a line to /home/admin/cron/log (file) every 5 minutes, but /home/admin/cron/log (file) has nothing; cat log shows nothing. Apparently, the shell script is not working (or cron job is not set up right). What is the problem here?
     
    ohcnetwork, Dec 30, 2005 IP