problem in -->df command monitoring script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem in -->df command monitoring script
# 1  
Old 02-20-2012
problem in -->df command monitoring script

Hi All,

I am creating df monitoring script. but facing some below problm.

Please see the below code.

Code:
 
df_threshold=90;
for i in `cat df_fnl.txt`
do
if [ $(echo "$i > $df_threshold"|bc) -eq 1 ] ; then
echo "%df is more than $df_threshold "
fi
done



and df_fnl.txt contains the data....
Code:
 
50%
5%
Use%
1%
11%


but it giving me the below error-

Code:
./df.sh: line 17: [: -eq: unary operator expected
(standard_in) 1: syntax error
./df.sh: line 17: [: -eq: unary operator expected
(standard_in) 1: illegal character: U
(standard_in) 1: syntax error
./df.sh: line 17: [: -eq: unary operator expected
(standard_in) 1: syntax error
./df.sh: line 17: [: -eq: unary operator expected
(standard_in) 1: syntax error
./df.sh: line 17: [: -eq: unary operator expected

Please help me to solve the above error .

and how can i remove % symbol from df_fnl.txt file.

so that it will be easier me to compair the values.


Thanks
# 2  
Old 02-20-2012
Code:
#! /bin/bash
df_threshold=90;
while read x
do
    x=${x%\%}
    echo $x | egrep -q "^[0-9]*$"
    [ $? -ne 0 ] && continue
    if [ $(echo "$x > $df_threshold"|bc) -eq 1 ] ; then
        echo "$x is more than $df_threshold "
    fi
done < df_fnl.txt

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 02-20-2012
Hello Aish11 ,

In order to remove the % symbol in your sample input file use

Code:
for i in `cat df_fnl.txt |  sed 's/%//g'`

Does the below code segment is what you need ?

Code:
df_threshold=90;
for i in `cat df_fnl.txt |  sed 's/%//g'`
do
if [[ $i -gt $df_threshold ]] ; then
echo "%df is more than $df_threshold "
fi
done

This User Gave Thanks to codemaniac For This Post:
# 4  
Old 02-20-2012
Use "-gt" insted of symbol ">" .

--Shirish
# 5  
Old 02-20-2012
Thanks balajesuri and codemaniac .

your code is working.

---------- Post updated at 04:43 AM ---------- Previous update was at 04:40 AM ----------

Quote:
Originally Posted by balajesuri
Code:
#! /bin/bash
df_threshold=90;
while read x
do
    x=${x%\%}
    echo $x | egrep -q "^[0-9]*$"
    [ $? -ne 0 ] && continue
    if [ $(echo "$x > $df_threshold"|bc) -eq 1 ] ; then
        echo "$x is more than $df_threshold "
    fi
done < df_fnl.txt


Hi balajesuri,

can u plz explain me the below code?? how it removes the % symbol

Code:
x=${x%\%}
    echo $x | egrep -q "^[0-9]*$"

# 6  
Old 02-20-2012
Code:
 
x=${x%\%}

Read about the bash string manipulation.

Manipulating Strings
# 7  
Old 02-20-2012
@aish11: ${x%\%} --> Removes the shortest match of a pattern from the end of string. So, in this case, it finds for % (which is escaped) from the end and removes it.

echo $x | egrep -q "^[0-9]*$" --> This line checks if the line being read contains only a number after removing %. I saw an entry in df_fnl.txt is 'Use%', which doesn't form a valid number after removing % symbol and hence this check.

And as codemaniac and Shirishlnx suggested, use -gt rather than using > and invoking bc.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Infrastructure Monitoring

Problem with service monitoring

This morning we had an activity on our Nagios server, whereby we inserted new disks into the server, and rebooted the server. The disk implementation failed, therefore we had to revoke the changes, and rebooted the server once again. The server was up and running at 6:00 am this morning.... (2 Replies)
Discussion started by: anaigini45
2 Replies

2. IP Networking

Network Interfaces Problem - Monitoring equipment

Dear gurus of Linux / Unix. I have a server, which I use to monitoring traffic, the problem that I find is when I run the following command: probe:~ # sar -n DEV 1 I see that I one second appear info in some interface and in the other second no appear, I don't know what will be the... (0 Replies)
Discussion started by: andresguillen
0 Replies

3. Shell Programming and Scripting

Problem with expr command in shell script

Hi, I have used expr command to increment the date. for e.g., case 1 : echo $(date -d $(echo `expr 20010101 + 1`)) it returns Tue Jan 2 00:00:00 IST 2001 case 2: echo $(date -d $(echo `expr 20010101 - 1`)) it returns date: invalid date `20010100' please suggest me, how to... (3 Replies)
Discussion started by: nanthagopal
3 Replies

4. UNIX for Dummies Questions & Answers

problem with awk command in script.

#!/bin/sh date=`date +%y%m%d -d"1 day ago"` inbound_dir=/vis/logfiles/to_solmis cp `grep -il ST~856~ $inbound_dir/*$date*` /vis/sumit/in_ASN/ echo 'SENDER,RECEIVER,DATE,TIME,ASNUMBER' > a.csv for i in /vis/sumit/in_ASN/* do ... (8 Replies)
Discussion started by: shrima.pratima
8 Replies

5. Shell Programming and Scripting

Grabbing value from command output and monitoring for changes

Hi all, Very new to shell scripting so appreciate some help! There is a process count that I need to monitor, I have the AIX command that gives this value and I've cleaned it up with grep/awk so it only spits out the value I'm interested in: echo "psc -i 10050 -s RELOAD_SERVICE" | tmadmin... (14 Replies)
Discussion started by: monty77
14 Replies

6. Linux

Help in monitoring performance problem in Linux

hello, i'm having some performance problem on one of my linux machines and i hope someone will be able to help me analyzing the problem. machine info: Linux fedora, cpu x 4 cores of 1.6Ghz, 8G memory, 8G swap. i've enabled sar on my machine and created a graph using ksar utility for... (15 Replies)
Discussion started by: levic
15 Replies

7. Shell Programming and Scripting

Problem with MV command in Shell Script

Hi Guru's, I 'm trying to execute the below given script in Unix. I am having an issue with the script. The output of the script is given below: #!/bin/bash File_Home="/home/essftp/Risk" cd /home/essftp/Risk rm -f FileList rm -f credit_risk* file1=`ls -lt... (4 Replies)
Discussion started by: ranjith_taurean
4 Replies

8. UNIX for Dummies Questions & Answers

command out of script problem

I wanna put a LDAP search command into a script and there I have the following problem. I have these variables in a bash script com="ldapsearch -LLL -x -W" node=" -b 'o=me,ou=addressbook,dc=subdomain,dc=dyndns,dc=org'" uri=" -H ldaps://subdomain.dyndns.org" user=" -D... (2 Replies)
Discussion started by: borobudur
2 Replies

9. Filesystems, Disks and Memory

disk and memory monitoring problem

Hi all, I am looking for api to get me system monitoring statictics every 5 minutes. I am looking at the following statistics: 1. System CPU Usage 2. Process CPU Usage 3. Process Memory Usage 4. I/O Usage for a certain disk. 5. Process I/O bytes/sec utilization. I have seen very... (2 Replies)
Discussion started by: uiqbal
2 Replies

10. Shell Programming and Scripting

problem with sed command in shell script.

Guys, I've a problem in the "sed" command used in my shellscripts This is the problamatic line in my shell script: sed -e 's/${line1}/${line1_m}/g' prod_hier_1234.txt > test.txt It doesn't do the job of replacing the string stored in variable 'line1' to 'line1_m'. However If I replace the... (10 Replies)
Discussion started by: bhagat.singh-j
10 Replies
Login or Register to Ask a Question