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

Re: Learning Scripting



Thanx, Michael and Andrew. Here is my first usable shell script, thanx to your help.

The idea was the system cannot start the X-Server sometimes when the power goes off unexpectedly. So, if an error message is found the system should be shutdown nicely and then when it reboots, it runs an fsck and cleans up.

The second set of checks is because sometimes the grep command itself appears in the ps ax, and we do not want to reboot for this spurious occurrence.

#!/bin/sh

msg1="/etc/gdm/XKeepsCrashing -noopen"
msg2="yesno I cannot start the X server"

check1=$(ps ax | grep -i "$msg1")
count1=${#check1}
check10=$(echo $check1 | grep -i "grep")
count10=${#check10}

check2=$(ps ax | grep -i "$msg2")
count2=${#check2}
check20=$(echo $check2 | grep -i "grep")
count20=${#check20}

if [ $count10 -gt 0 ]
then
   count1=0
fi

if [ $count20 -gt 0 ]
then
   count2=0
fi

if [ $count1 -gt 0 ] || [ $count2 -gt 0 ]
 then
   echo "Found it!"
   shutdown -r now
 else
   echo "Not found!"
fi


Anil Gupte
www.keeninc.net
www.icinema.com

----- Original Message ----- From: "Andrew Sackville-West" <andrew@farwestbilliards.com>
To: <debian-user@lists.debian.org>
Sent: Monday, May 15, 2006 11:29 PM
Subject: Re: Learning Scripting




Reply to: