943,691 Members | Top Members by Rank

Ad:
Nov 10th, 2008
0

weird output

Expand Post »
I had a similar script in solaris and it had no problem. I wrote this one in freeBSD and it gave me strange output. Can anyone please tell me why? thanks a lot

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/sh
  2. #This is a shell script that checks file system capacity mounted on /home directory
  3. #If file system is over 90% capacity, this shell script will generate notification emails sending to all users
  4.  
  5. warning()
  6. {
  7. fs=$1 # first argument is the file system name
  8. fscap=$2 # second argument is the file system's capacity
  9.  
  10. for user in `ls /home`
  11.  
  12. do
  13. echo "File system mounted on /home directory is over 90% capacity. Please be ready for system maintainance. " | mail -s "Warning! $fs here is at $fscap capacity" user
  14.  
  15. done
  16.  
  17. echo "Warning: $fs is at $fscap capacity"
  18. }
  19.  
  20. daOslg= `df -h | sed -n '/home/p' | tr -s ' ' ' ' | cut -d' ' -f1`
  21. daOslgCap= `df -h | sed -n '/home/p' | tr -s ' ' ' ' | cut -d' ' -f5`
  22.  
  23. if ["$daOslgCap" -gt "90%"]
  24. then
  25. warning $daOslg $daOslgCap
  26. fi
  27.  

output:
Shell Scripting Syntax (Toggle Plain Text)
  1.  
  2. $ ./capChecker
  3. ./capChecker: /dev/da0s1g: Permission denied
  4. 0%: not found
  5. [: missing ]
Similar Threads
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007
Nov 11th, 2008
0

Re: weird output

Hey there,

I think definitely you'll see some differences in performance. Solaris' sh is the bourne shell and a lot of linux/bsd distro's just like sh to bash or another shell.

The one thing I saw that jumped out at me was:

if ["$daOslgCap" -gt "90%"]

there may be 2 issues with this. Try padding spaces in between the [] and, possibly, check and see if there's an issue with the sense of your "if check", since "90%" is an alpha value and -gt is a unary comparison operator.

to add the spaces:
Quote ...
if [ "$daOslgCap" -gt "90%" ]
for the other part, you should clip the % from your value so you'll be checking if
Quote ...
$daOslgCap -gt 90
Hope that helps you get closer to an answer, if it doesn't answer the whole thing. If you could post the output of :

Quote ...
/bin/sh -x capChecker
that might shed some more light.

Best wishes,

Mike
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: opening multiples files in awk?
Next Thread in Shell Scripting Forum Timeline: Anyone know anything about WINBATCH?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC