User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 422,422 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,352 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1348 | Replies: 5
Reply
Join Date: May 2008
Posts: 4
Reputation: rpnalluri is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rpnalluri rpnalluri is offline Offline
Newbie Poster

Script is not working in linux

  #1  
May 19th, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,588
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 22
Solved Threads: 411
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: Script is not working in linux

  #2  
May 19th, 2008
totalspacelist=`cat $DF|awk '{print $2}`

You're missing a '

Next time, use some code tags.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: May 2008
Posts: 4
Reputation: rpnalluri is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rpnalluri rpnalluri is offline Offline
Newbie Poster

Re: Script is not working in linux

  #3  
May 19th, 2008
Hello Salem,

Thank you for quick reply. After i changed those quotes from " ` " to " ' " , still i am getting some errors. can u pls advise me. But my previous script is working fine in solaris environment. /tmp directory have 777 permissions.

My prmiary goal with this script is i need to get FS stats for almost 50 servers and i have hostnames and file system names on different txt files. Is there a script to do this. I need to get total available space, current usage, available space and percentage for each file system mentioned in text file.

errors i am getting now
./dm1.sh: line 25: /tmp/df16376: Permission denied
./dm1.sh: command substitution: line 35: syntax error: unexpected end of file
./dm1.sh: line 30: 0: command not found
./dm1.sh: line 46: unexpected EOF while looking for matching `''
./dm1.sh: line 50: syntax error: unexpected end of file

below is the modified 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


Thanks
Reply With Quote  
Join Date: May 2008
Posts: 4
Reputation: rpnalluri is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rpnalluri rpnalluri is offline Offline
Newbie Poster

Re: Script is not working in linux

  #4  
May 19th, 2008
Hi,

I was able to troubleshoot that error, but now i am getting bellow error. Pls advise me.

"expr: non-numeric argument"

my modified 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


Thanks,
raja
Reply With Quote  
Join Date: Apr 2008
Location: Tulsa
Posts: 52
Reputation: khess is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
Staff Writer
Featured Blogger
khess's Avatar
khess khess is online now Online
Junior Poster in Training

Re: Script is not working in linux

  #5  
May 30th, 2008
DMLIST=dmlist
This is where your error is.

dmlist is not a linux command. if it were, you need to DMLIST=`dmlist`
Ken Hess
Linux Blogger/Columnist
Reply With Quote  
Join Date: May 2008
Posts: 4
Reputation: rpnalluri is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rpnalluri rpnalluri is offline Offline
Newbie Poster

Re: Script is not working in linux

  #6  
May 30th, 2008
Hi All,

Thank you for your response. Script is working now. I worked another way and it is working fine in linux also.
this is the script working fine in linux.
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|grep -v /dev>$DF

totalspacelist=`cat $DF|awk '{print $1}'`
totalusedlist=`cat $DF|awk '{print $2}'`
totalavailablelist=`cat $DF|awk '{print $3}'`

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
Last edited by ~s.o.s~ : May 31st, 2008 at 11:22 am. Reason: Added code tags, learn to use them.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 9:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC