Debugging Help Needed

Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Debugging Help Needed

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

I am VERY much a neophyte with shell scripting. I am working on the following,

1. The problem statement, all variables and given/known data:

"Create a script sends an email message to the user specified on the command line if any of the file
systems at more than 60% of capacity. The script should not process special file systems as /proc on
the ce.uml.edu. It should only process file systems which are either locally mounted or are mounted
via NFS.""Create a script sends an email message to the user specified on the command line if any of the file
systems at more than 60% of capacity. The script should not process special file systems as /proc on
the ce.uml.edu. It should only process file systems which are either locally mounted or are mounted
via NFS."

2. Relevant commands, code, scripts, algorithms:



3. The attempts at a solution (include all code and scripts):

Code:
#!/bin/bash
#  script to send an email message to the user specified on the command line if
# any of the file systems at more than 60% of capacity.

df -H | grep -vE '^Filesystem' | 'none' | awk '{ print $1 " " $5 }' | while read fsout
do
  echo "$fsout"
  partition=$(echo "$fsout" | awk '{ print $2 }' )
  usage=$(echo "$fsout" | awk '{ print $1 }' | cut -d'%' -f1)

  if [ $usage -ge 90 ]
  then
    echo "CRITICAL WARNING!!: Filesystem \"$partition\" at "$usage"% of capacity" |
    mail -s "CRITICAL WARNING!!: Filesystem \"$partition\" at "$usage"% of capacity" emailaddress@student.uml.edu

  elif [ $usage -ge 60 ] && [ $usage -lt 90 ]
  then
    echo "Warning!!: Filesystem \"$partition\" at "$usage"% of capacity" |
    mail -s "Warning!!: Filesystem \"$partition\" at "$usage"% of capacity" emailaddress@student.uml.edu
  fi
done

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University Of Massachusetts, Lowell, USA, Michael Richards, Linux/Unix System Administration

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

I am getting these errors:


Code:
./fsc.sh: line 4: $'\r': command not found
./fsc.sh: line 16: syntax error near unexpected token `elif'
'/fsc.sh: line 16: `  elif [ $usage -ge 60 ] && [ $usage -lt 90 ]

Any help is greatly appreciated.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by doghouse308; 02-25-2018 at 02:31 PM.. Reason: Added CODE tags.
# 2  
It appears your script has Windows style carriage return (CR) characters (\r) present, which are messing up things.
These can be removed like this:
Code:
tr -d '\r' < oldscript > newscript



--
Unix/Linux uses LF line endings (Line Feed), while Windows uses CRLF endings (Carriage Return / Line Feed).
# 3  
We're getting closer.

Now getting

Code:
./fsc2.sh: line 11: [: udev: integer expression expected
./fsc2.sh: line 16: [: udev: integer expression expected
tmpfs 1%
./fsc2.sh: line 11: [: tmpfs: integer expression expected
./fsc2.sh: line 16: [: tmpfs: integer expression expected
/dev/dm-0 5%
./fsc2.sh: line 11: [: /dev/dm-0: integer expression expected
./fsc2.sh: line 16: [: /dev/dm-0: integer expression expected
none 0%
./fsc2.sh: line 11: [: none: integer expression expected
./fsc2.sh: line 16: [: none: integer expression expected
none 0%
./fsc2.sh: line 11: [: none: integer expression expected
./fsc2.sh: line 16: [: none: integer expression expected
none 1%
./fsc2.sh: line 11: [: none: integer expression expected
./fsc2.sh: line 16: [: none: integer expression expected
none 1%
./fsc2.sh: line 11: [: none: integer expression expected
./fsc2.sh: line 16: [: none: integer expression expected
/dev/sda1 14%
./fsc2.sh: line 11: [: /dev/sda1: integer expression expected
./fsc2.sh: line 16: [: /dev/sda1: integer expression expected
ce.uml.edu:/users/ 16%
./fsc2.sh: line 11: [: ce.uml.edu:/users/: integer expression expected
./fsc2.sh: line 16: [: ce.uml.edu:/users/: integer expression expected
ce.uml.edu:/space/ 36%
./fsc2.sh: line 11: [: ce.uml.edu:/space/: integer expression expected
./fsc2.sh: line 16: [: ce.uml.edu:/space/: integer expression expected

Will quotations around $usage and or the number eliminate these errors?


Moderator's Comments:
Mod Comment Please use CODE tags (for output / data as well) as required by forum rules!

Last edited by RudiC; 02-25-2018 at 02:33 PM.. Reason: Added CODE tags.
# 4  
Code:
usage=$(echo "$fsout" | awk '{ print $1 }' | cut -d'%' -f1)

If this is correct ( syntax...), it doesnt make the value an integer... thus the error
e.g. in ksh, I would use let
# 5  
Sure | 'none' | is a valid command?
In lieu of your while read fsout you could read individual variables and get rid of many of your conversions / extractions.
Sure usage is $1?
# 6  
I added the let that you suggested and got this:

Code:
udev 1%
tmpfs 1%
/dev/dm-0 5%
./fsc.sh: line 9: let: usage=/dev/dm-0: syntax error: operand expected (error token is "/dev/dm-0")
none 0%
none 0%
none 1%
none 1%
/dev/sda1 14%
./fsc.sh: line 9: let: usage=/dev/sda1: syntax error: operand expected (error token is "/dev/sda1")
ce.uml.edu:/users/ 16%
./fsc.sh: line 9: let: usage=ce.uml.edu:/users/: syntax error: invalid arithmetic operator (error token is ".uml.edu:/users/")
ce.uml.edu:/space/ 36%
./fsc.sh: line 9: let: usage=ce.uml.edu:/space/: syntax error: invalid arithmetic operator (error token is ".uml.edu:/space/")

---------- Post updated at 01:50 PM ---------- Previous update was at 01:46 PM ----------

Quote:
Originally Posted by RudiC
Sure | 'none' | is a valid command?
In lieu of your while read fsout you could read individual variables and get rid of many of your conversions / extractions.
Sure usage is $1?
Honestly, not sure of much at this point. I've gone so many different directions with this I don't recall what lead me from one decision to another.

The script currently looks like this

Code:
#!/bin/bash
#  script to send an email message to the user specified on the command line if
# any of the file systems at more than 60% of capacity.

df -H | grep -vE '^Filesystem | none' | awk '{ print $1 " " $5 }' | while read -r fsout
do
  echo "$fsout"
  partition=$(echo "$fsout" | awk '{ print $2 }' )
  let usage=$(echo "$fsout" | awk '{ print $1 }' | cut -d'%' -f1)

  if [ "$usage" -ge "90" ]
  then
    echo "CRITICAL WARNING!!: Filesystem \"$partition\" at \"$usage\"% of capacity" | \
    mail -s "CRITICAL WARNING!!: Filesystem \"$partition\" at \"$usage\"% of capacity" emailaddress@student.uml.edu

  elif [ "$usage" -ge "60" ] && [ "$usage" -lt "90" ]
  then
    echo "Warning!!: Filesystem \"$partition\" at \"$usage\"% of capacity" | \
    mail -s "Warning!!: Filesystem \"$partition\" at \"$usage\"% of capacity" emailaddress@student.uml.edu
  fi
done

---------- Post updated at 02:04 PM ---------- Previous update was at 01:50 PM ----------

Thank you! No, usage was not 1, it was two. Working now!

Last edited by Don Cragun; 02-25-2018 at 07:40 PM.. Reason: Add CODE and ICODE tags.
# 7  
Glad our clues helped you out...
Thanks for keeping us informed, and good luck for the future
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Debugging Help needed
doghouse308
I am VERY much a neophyte with shell scripting. I am working on the following, "Create a script sends an email message to the user specified on the command line if any of the file systems at more than 60% of capacity. The script should not process special file systems as /proc on the...... UNIX for Beginners Questions & Answers
2
UNIX for Beginners Questions & Answers
c++ debugging
gotenxds
hey i have a problem with a switch case in program and the debugger is messy has hell ( we use normal VI and gdb in our schoool to make it more diffiacult) any way i have a problom where for some unknown reason the debugger just skips a switch statment as if it wasent even there the rest...... Programming
2
Programming
debugging
satish@123
when I tried to debug my application i got the following. gdb -v GNU gdb 6.6 file is in C and Xmotiff Languages (gdb) attach 25499 Attaching to process 25499 Retry #1: Retry #2: Retry #3: Retry #4: 0xfea40b68 in ?? () (gdb) where #0 0xfea40b68 in ?? ()... Solaris
0
Solaris
debugging in bash!!! help needed
wrapster
Hi all, Am using bash shell. Am newbie, trying to understand the debugin process of a shell script... I am unable to comprehend the control flow ,meaning from where exactly the execution of the script begins... I tried using bash-xv <scriptname> but since am new ,am finding it difficult to...... Shell Programming and Scripting
2
Shell Programming and Scripting
Regarding Debugging
sarwan
Hi, If we want to debug a shell script, then set -vx has to be included in the begining of the script. Just i want to know what purpose -vx is used. Thanks in advace Sarwan... Shell Programming and Scripting
2
Shell Programming and Scripting

Featured Tech Videos