Hello,
I have script to gather total FS usage size. I use to list of the FS's in another notepad file and this script will read from that file. finally it will give me output of total allocated space, used space, available space and percentage of space. This script works for me in solaris, but when i am trying to run in linux i am getting error. Please advise me on this.
script:
#!/bin/sh
# Get disk metrics and outpt in csv format
DMLIST=dmlist
DF=/tmp/df$$
HOSTNAME=`hostname`
totalspace=0
totalused=0
totalavailable=0
LOGDIR=/folk/rnalluri/vobscripts/data.out
LOGFILE=${LOGDIR}/`hostname``date +%m%d%y`.disk
cd /folk/rnalluri/vobscripts
if [ ! -d $LOGDIR ]
then
echo "Making $LOGDIR"
mkdir $LOGDIR
fi
#
#Grab list for this host from our config file
#
grep "^$HOSTNAME " $DMLIST |awk '{print $2}'|xargs df -k|grep -v Filesystem>$DF
totalspacelist=`cat $DF|awk '{print $2}`
totalusedlist=`cat $DF|awk '{print $3}`
totalavailablelist=`cat $DF|awk '{print $4}`
for i in $totalspacelist
do
totalspace=`expr $totalspace + $i`
done
for i in $totalusedlist
do
totalused=`expr $totalused + $i`
done
for i in $totalavailablelist
do
totalavailable=`expr $totalavailable + $i`
done
totalspace=`expr $totalspace / 1024000`
totalused=`expr $totalused / 1024000`
totalavailable=`expr $totalavailable / 1024000`
totalpercent=`echo $totalused $totalspace|awk '{printf "%2.0f",$1/$2*100}`
echo "server,total space,used space,available space, %used" | tee $LOGFILE
echo "$HOSTNAME,${totalspace}GB,${totalused}GB,${totalavailable}GB,$totalpercent"|tee -a $LOGFILE
/bin/rm $DF
Below is the error when i tried to run in linux i am getting. I am using RHEL 4 & 5.
sh-3.00$ ./dm1.sh
./dm1.sh: command substitution: line 24: unexpected EOF while looking for matching `''
./dm1.sh: command substitution: line 25: syntax error: unexpected end of file
./dm1.sh: command substitution: line 25: unexpected EOF while looking for matching `''
./dm1.sh: command substitution: line 26: syntax error: unexpected end of file
./dm1.sh: command substitution: line 26: unexpected EOF while looking for matching `''
./dm1.sh: command substitution: line 27: syntax error: unexpected end of file
./dm1.sh: command substitution: line 46: unexpected EOF while looking for matching `''
./dm1.sh: command substitution: line 47: syntax error: unexpected end of file
server,total space,used space,available space, %used
Thanks,
raja