#!/bin/bash
function sanityCheck {
q=`ps -ef |grep $0 |grep -v "grep"|grep -v $$| wc -l`
if [ $q != "0" ]; then
echo "Another instance of $0 running..."
exit 1
fi
}function start {
sanityCheck
echo "Starting daemon..."
main
}function shutdown {
echo "Shutting down daemon..."
kill `ps -ef |grep $0|grep -v $$ |grep -v "grep"|awk '{print($2)}'`
}function main {
{
while [ 1 ]; do
echo "PROVA..."
sleep 2
done
} &
}case $1 in
"start")
start
;;
"shutdown")
shutdown
;;
*)
start
;;
esac
Utilizzo :
# chmod +x ./daemon-test.sh
# ./daemon-test.sh
Starting daemon...
PROVA...
# PROVA...PROVA...PROVA...
# ./daemon-test.sh shutdown
Shutting down daemon...
(486)