Monday, November 28, 2011

Script to Alert when server is UP and running

The inspiration which led me to making this script was because of a couple of reasons. Firstly because the internet connectivity is intermittent here, so i run this script and check for google.com hence I will get notified when connection is back unless google is down ;) .

The second reason is that I work on a lot of servers and when a server is gone for a reboot, I can run this script and give the server IP as input hence I will get notified when server is back online.

++++++++++++++++++++++++++++++++++++++
#!/bin/bash
echo "Enter ip/domain name"
read a
HOSTS=$a
COUNT=4
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 4 ]; then
# 100% Up
echo "Host : $myHost is Working (ping Sucess) at $(date)"
fi
done
++++++++++++++++++++++++++++++++++++++

Change Wallpaper Script

The script below will change the wallpaper by randomly selecting a picture from a directory specified. For the script to work you will have to add it as a cron and set the interval of your choice for the wallpaper change.
 
Open your favourite editor and paste the codes below:
+++++++++++++++++++++++++
#!/bin/bash

# Directory Containing Pictures
DIR=/home/hari/Pictures
LOG=/home/hari/tapeta.log

# Command to Select a random file from directory
PIC="$(
for p in [jJ][pP][gG] [pP][nN][gG] ; do
ls $DIR/*.$p
done | shuf -n1
)"

# Command to set Background Image
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] ; then

# this is because of gconftool bug in cron
TMP=~/.dbus/session-bus
export $(grep -h DBUS_SESSION_BUS_ADDRESS= $TMP/$(ls -1t $TMP | head -n 1))
echo $DBUS_SESSION_BUS_ADDRESS >> $LOG
fi

gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$PIC"
+++++++++++++++++++++++++

Note: Tested in Fedora 14 and working fine. Should work in centos and other red hat flavours.
Reffered: http://stackoverflow.com/questions/2182468/run-cronjob-as-user-to-change-desktop-background-in-ubuntu

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews