•
•
•
•
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 397,581 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 3,190 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:
Views: 1170 | Replies: 5
![]() |
•
•
Join Date: May 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
totalspacelist=`cat $DF|awk '{print $2}`
You're missing a '
Next time, use some code tags.
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.
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.
•
•
Join Date: May 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
•
•
Join Date: May 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
•
•
Join Date: May 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
age apple core dell desktop development drm energy enterprise fedora games gentoo gnome gpl hardware ibm it itunes kde laptop linux microsoft mmorpg mobile news novell office olpc open open source openoffice operating os pc pirate ps3 red hat remote working russia security software source sun system ubuntu unix vista web windows x86
- download pdf file, convert to html, in PHP since working in Linux (PHP)
- 500 internal server error (*nix Software)
- script not working in RedHat Linux. (Shell Scripting)
- "system" function (PHP)
- help with shell script padding files with spaces (Shell Scripting)
- form validation not working (JavaScript / DHTML / AJAX)
- script for search SUID/GUID ! (Shell Scripting)
- i don't know how to install linux (*nix Software)
Other Threads in the Shell Scripting Forum
- Previous Thread: editting questions
- Next Thread: new to linux shell script???????



Linear Mode