#Useful Shell Script for System Administrators
#Monitoring a filesystem usage when the space available reachedcertain limit, this script will email.
#Just run the following script in backround
#To run a script in backround:
#$sh script_name & (or)
#$./script_name &
#!/bin/ksh
while true
do
usage=`df -k /tmp |grep -v Filesystem|awk '{print $5}'|cut -c 1-2`
while((usage<=25))
do
usage=`df -k /tmp |grep -v Filesystem|awk '{print $5}'|cut -c 1-2`
done
echo "The /tmp filesytem on `hostname` is $usage % Please clear the space"|mail -s "disk space used" v.nandha@gmail.com
sleep 600
done
#Awesome cut command
if your file has the strings continously, and want to split at specified intervals
ex: file a.txt contains
121rsfgfggtetert5366654gfdggh5ryrhfghgfrtyrtfghfghtryryryr
121rsfgfggtetert5366654gfdggh5ryrhfghgfrtyrtfghfghtryryryr
121rsfgfggtetert5366654gfdggh5ryrhfghgfrtyrtfghfghtryryryr
cat a.txt | cut -c 1-5,6-16,17-23,24-$$ --output-delimiter=" : "
$$ - denotes end of line in bash
Output:
121rs : fgfggtetert : 5366654 : gfdggh5ryrhfghgfrtyrtfghfghtryryryr
121rs : fgfggtetert : 5366654 : gfdggh5ryrhfghgfrtyrtfghfghtryryryr
121rs : fgfggtetert : 5366654 : gfdggh5ryrhfghgfrtyrtfghfghtryryryr
No comments:
Post a Comment