The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
invoking a shell script inside cgi shell script smriti_shridhar Shell Programming and Scripting 2 07-09-2008 01:50 AM
Accessing variables of one shell script in another shell script looza Shell Programming and Scripting 2 06-30-2008 07:13 PM
How to pass a parameter from one Shell-script to another Shell-script subodhbansal Shell Programming and Scripting 2 09-22-2007 05:19 AM
How to Run a shell script from Perl script in Parent shell? hifake Shell Programming and Scripting 16 08-28-2007 08:42 PM
Have a shell script call another shell script and exit heprox Shell Programming and Scripting 2 11-20-2006 08:17 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-26-2008
rohit22hamirpur rohit22hamirpur is offline
Registered User
  
 

Join Date: Nov 2008
Location: delhi
Posts: 8
shell script -- need help

check all the file system if any file system is using above 80% space then an automatic mail with all mount point details send to abc@yahoo.com on each monday at 5:30pm.Please help me on this script.

Thanks in advance
Rohit
  #2 (permalink)  
Old 11-26-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
Here is a script we use on our HP-UX servers, it runs in cron wvery 30mins and would immediately send out an email.

There are actually 2 warning levels, Warning and EMERGENCY.
Code:
 n[1]=1; fs[1]=/; limit1[1]=70; limit2[1]=80;
this line sends a warning at 70% and EMERGENCY at 80% for root.

Code:

#!/usr/bin/ksh

# Setup the date variables
FullDate=`date`
Date=`date +%m%d`

# Setup the other variables
ProgName=checkfilesystem
SCRIPTDIR=/local/bin/
LOG=/syslog/filecheck.log
TMP=/tmp/${ProgName}.$$
TMP2=/tmp/${ProgName}.${$}.2
MAILSUPPORT="someemail@email.com"

# Setup the Node name
host=`hostname`

#Here are the filesystems which are checked

  n[1]=1; fs[1]=/; limit1[1]=70; limit2[1]=80;
  n[2]=2; fs[2]=/var; limit1[2]=80; limit2[2]=90;
  n[3]=3; fs[3]=/usr; limit1[3]=80; limit2[3]=95;
  n[4]=4; fs[4]=/tmp; limit1[4]=50; limit2[4]=90;
  n[5]=5; fs[5]=/home; limit1[5]=70; limit2[5]=90;
  n[6]=6; fs[6]=/stand; limit1[6]=60; limit2[6]=80;
  n[7]=7; fs[7]=/opt; limit1[7]=80; limit2[7]=90;


  #...End of locally modifyable section

exec > $LOG 2>&1


  for x in ${n[*]}
  do
  xfs=${fs[$x]}
  l1=${limit1[$x]}
  l2=${limit2[$x]}
  pctfull=`df -k $xfs|grep allocation |awk '{print $1}'|tr -d '%'`
  if (( $pctfull > $l2 )); then
echo "EMERGENCE EMERGENCY EMERGENCY"
echo "$xfs=$pctfull on $host"
echo "Check filesystem and solve the problem"
echo

else
  if (( $pctfull >= $l1)); then

echo "Warning $xfs=$pctfull on $host"
echo "Please check the filesystem"
echo
fi
fi
done
        if [[ -s $LOG && -f $LOG ]]; then
        mailx -s "Filesystem Problem on $host " $MAILSUPPORT < $LOG
        fi
  #3 (permalink)  
Old 11-26-2008
rohit22hamirpur rohit22hamirpur is offline
Registered User
  
 

Join Date: Nov 2008
Location: delhi
Posts: 8
Hi ,

I use df then I found that kind of filesystem.Please look into it.

[efare@e1dsgalnggf10] $ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 2747140 417256 2190336 17% /
/dev/sda1 175900 16085 150733 10% /boot
none 16637248 0 16637248 0% /dev/shm
/dev/sda9 14167456 4996728 8451044 38% /home
/dev/sda6 3752552 1372648 2189280 39% /opt
/dev/sda8 1832060 54520 1684476 4% /tmp
/dev/sda5 4580244 2299052 2048528 53% /usr
/dev/sda7 3668032 2625440 856264 76% /var
ecmcc03:/ecmvobstore 31260672 16519168 14741504 53% /ecmvobstore
ecmcc04:/vwsstg 103001368 29822408 67946736 31% /vwsstg
e1dsgalnggfns01:/vol/dev_logstats
75157224 39457656 35699568 53% /dev_logstats
e1dsgalnggfns02:/vol/dev_tools
288102672 251549088 36553584 88% /dev_tools
e1dfgalnggfns02:/vol/dev_tools/LINUXMTP-4
288102672 251549088 36553584 88% /dev_tools/MTP
e1dfgalnggfns02:/vol/dev_tools/LOCAL4-T2
288102672 251549088 36553584 88% /usr/local
e1dfgalnggfns02:/vol/dev_tools/LOCAL4-T2
288102672 251549088 36553584 88% /dev_tools/efare1/dist/sparc
e1dsgalnggfns02:/vol/dev_tools/efare1/dist/sparc/home
288102672 251549088 36553584 88% /dev_tools/efare1/dist/sparc/home
/dev/mvfs 2747140 417256 2190336 17% /view
/ecmvobstore/scm_scripts.vbs
31260672 16519168 14741504 53% /vob/scm_scripts
/ecmvobstore/ctg.vbs 31260672 16519168 14741504 53% /vob/ctg
/ecmvobstore/css.vbs 31260672 16519168 14741504 53% /vob/css
/ecmvobstore/test_dst.vbs
31260672 16519168 14741504 53% /vob/test_dst
/ecmvobstore/efs.vbs 31260672 16519168 14741504 53% /vob/efs
e1dsgalnggfns01:/vol/dev_histgold2
3114417528 3027308912 87108616 98% /uefare1/dev_histgold2
e1dsgalnggfns01:/vol/dev_histgold1
3114417528 3035423568 78993960 98% /uefare1/dev_histgold1

Is this script run on this output.Beacuse mailsent when it is above 80%.

Last edited by rohit22hamirpur; 11-26-2008 at 06:34 PM.. Reason: clarify more
  #4 (permalink)  
Old 11-27-2008
adhit adhit is offline
Registered User
  
 

Join Date: Apr 2008
Location: Jakarta
Posts: 11
Hi,

please try this
flag=0
touch /tmp/testaja.txt
bdf|awk '{print $5" "$6}'|while read output;
do
persen=$(echo $output |awk -F "%" '{print $1}')
dir=$(echo $output |awk '{print $2}')
if [ $persen -gt 80 ]; then
echo "$dir $persen" >> /tmp/testaja.txt
flag=1
fi
done
if [ $flag -eq 1]; then
mail yourmail@somewhere.com < /tmp/testaja.txt
fi

thanks
  #5 (permalink)  
Old 12-03-2008
rohit22hamirpur rohit22hamirpur is offline
Registered User
  
 

Join Date: Nov 2008
Location: delhi
Posts: 8
Hi Adhit,

I will try this script.

Thanks in advance-
Rohit

Last edited by rohit22hamirpur; 12-03-2008 at 07:06 PM..
Sponsored Links
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0