Archive for the ‘Linux-Scripts’ Category


Nice Script to display Date and time .
Ref : http://bashscript.blogspot.com/

#!/bin/bash
# SCRIPT: digclock.sh
# USAGE:  ./digiclock &
# PURPOSE: Displays time and date in the top right corner of the
#          screen using tput command.
# To stop this digclock use command "kill pid"
################################################################

####################### VARIABLE DECLARATION ###################

 # To place the clock on the appropriate column, subtract the
 # length of $Time and $Date, which is 22, from the total number
 # of columns

  Columns=$(tput cols)
  Startpoint=$(($Columns-22))

 # If you're in an X Window System terminal,you can resize the
 # window, and the clock will adjust its position because it is
 # displayed at the last column minus 22 characters.

  Color1=`tput setab 2`        # Green background color for time
  Color2=`tput setab 6`        # Cyan  background color for date
  Normal=`tput sgr0`           # back to normal screen colors

####################### MAIN PROGRAM ###########################

# The script is executed inside a while without conditions

while :
do
  Time=`date +%r`
  Date=`date +"%d-%m-%Y"`
  tput sc                   #Save the cursor position&attributes
  tput cup 0 $Startpoint

 # You can also use bellow one liner
 # tput cup 0 $((`tput cols`-22))
 # But it is not efficient to calculate cursor position for each
 # iteration. That's why I placed variable assignment before
 # beginning of the loop.

 # print time and date in the top right corner of the screen.

  echo -n $Color1$Time $Color2$Date$Normal

 # restore the cursor to whatever was its previous position

  tput rc

 # Delay for 1 second

  sleep 1

done

How to use RSYNC

Posted: May 26, 2011 in Linux-Scripts, Redhat
Tags:

How do I use rsync command?

if you would like to sync’d between www1 and www2(master) servers, type the following command on www1 server:rsync -avrR --links --rsh=/usr/bin/ssh WWW2:/var/html/ /var/htmlWhere,

  • -avrR : archive mode (a), verbose (v), recurse into directories (r), use relative path names (R) [ I did not use R in my scripts for simplicity ]
  • –links : copy symlinks as symlinks
  • –delete                delete files that dont exist on master
    –rsh=/usr/bin/ssh : Use to specify the remote shell ssh to use (secure copy).
  • WWW2:/var/html/ : WWW2 server IP address and path to synchronize to www1 server
  • /var/html : WWW1 server path

A sample shell script for same job

#/bin/bash

MASTER="10.90.0.33"
DIR="/u01/backups/WMS852/online/"
LDIR="/u04/wms852bkup/online"
SSH="/usr/bin/ssh"
rsync -avr --links --delete --rsh=$SSH $MASTER:$DIR $LDIR


This will monitor the Disk space of a Linux system and send an email to ADMIN . Admin , and Thresold is a variable , so that it can be change accordingly.

===================================================

#!/bin/bash
#       This script determines the percentage of disk usage.
#       If that percentage is greater than 90% a user is emailed
#       a report notifying them of the usage.
#

emailUser=”it.support@au.specsavers.com,brandont@au.specsavers.com”
typeset -i error=”70″
if [ -e temp.txt ]; then
rm temp.txt
fi
for disc in `mount| egrep ‘^/dev’ | egrep -iv ‘cdrom|proc|sys|pts’ |awk ‘{print $3}’`
do
typeset -i discUsage=`df -h $disc|cut -c40-42|grep -i [^a-z]`
if [ “$discUsage” -ge “$error” ]; then
echo “Disc usage for $disc is at $discUsage. Need your attention !!%” >> temp.txt
fi
done
if [ -e temp.txt ]; then
message=`cat temp.txt`
fi
if [ ${#message} -gt 0 ]; then
cat temp.txt | mail  -s “Disc Usage exceed 70% for : $HOSTNAME” $emailUser
fi

===================================================