[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[OT] secure script without cron?



I've been searching though the archives, HOWTO's and online.  Can't seem
to find what I'm looking for.  Networking on my mail server stopped
working the other day.  Restarting the network solved the glitch.  

I've created the script below to automate this in the event it happens
again.  My question is, how do I run this script in a secure manner?
"/etc/init.d/networking restart." needs to be started as root.  

If I set it up in cron and restarting the network doesn't solve the
problem, "networking" will be in a loop.  I could source the command
/etc/init.d/networking restart" from a file and in the event of a
failure "mv" the file so the cron job couldn't access "networking."
That seems like a clunky hack.  I don't think sudo will work in this
situation.

Any thoughts or pointers appreciated.
Thanks,
kent

#!/bin/sh
# cheknet
 
while [ true ]; do
    ping -qc 2 10.10.10.9 &> /dev/null
 
    if [ "$?" -eq 0 ]; then
        echo "*** $(date)" >> cheknet.log
    else
        echo "Network Down ***" >> cheknet.log
        /etc/init.d/networking restart >> cheknet.log
        echo "--- Network Restarted ---" >> cheknet.log
    exit
    fi
sleep 5s
done                                                                                                

-- 
 From seeing and seeing the seeing has become so exhausted
     First line of "The Panther" - R. M. Rilke




Reply to: