Sunday, February 1, 2015

Scripting makes your life easier !







Thought of the day was make your life easier... Learn and Develop



Why ??


A day before yesterday i ran into situation where i thought how can I've a check in place which can -

  • Check the status of service running on the server 
  • And the utilization level of a particular file system.

Though i'm a newbie in scripting and still exploring the world of automation but i was able to write a small code which does the required work.

What it does:

It checks the service status of a particular Linux OS service & the utilization level of the specified file system and send the output at the specified mail id.

How you can use it:

1) Copy it and save it in a .sh or .py format
2) Change the file permission to executable. You can do it by using the command

# chmod 700 <file_name>

3) You can either execute it manually or schedule it via cron / autosys jobs.

Happy Learning!


Script::

############################
#
# Script: To check the service status and file system utilization
#

# Date: 2015-01-30

#
# Version Update: 1.0 Piyush Chawla            
#
############################

TODAY=$(date)
HOST=$(hostname)
service=<service name>
email=<email id>

status=`df -kh /<File System> | awk '$1 !~ /^Filesystem/ { sub("%$", "", $5); print $4}'`

if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
subject="$TODAY status for $HOST"
echo "$service at $HOST host is running and File system utilization is at $status" | mail -s "$subject" $email
else
subject="$TODAY status for $HOST"
echo "$service at $HOST is stopped, kindly check! and file system utilization is at $status" | mail -s "$subject" $email
fi



No comments:

Post a Comment