LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-11-2012, 07:39 PM   #1
sandeepreddy.bommineni
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
diskspace.sh: line 10: syntax error: unexpected end of file


Hi All,

Here is my script,

df -H | grep -vE '^Filesystem|tmpfs|cdrom' |awk '{print $5 " " $6}' | while read output;
do
echo $output
user=$(echo $output |awk '{print $1}' |cut -d'%' -f1 )
partition=$(echo $output |awk '{print $2 }' )
if [ $used -ge 90 ]; then
echo "Running out of space \"Partition $partition_name ($used%)\" on $(hostname) as on $(date)"| mail -s "Alert: Almost out of disk space $used%" sandeep@gmail.com, dba@gmail.com
fi
done



my script contains only 9 lines but it shows error at 10th line.

Thanks,
sandeep
 
Old 01-11-2012, 08:18 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
To debug common shell script problems run the script with 'sh -vx /path/to/script' as you'll see the commands and variables and such filled in. Anyway: unprotected (quoting) variable names, inconsistent variable names, unnecessary use of commands, inefficient alert message, here's an easy version:
Code:
#!/bin/sh --
df -H|awk '/\/dev\// {print $5, $1, $6}'|while read PERC DEV MOUNT; do
 [ ${PERC//%/} -ge 70 ] && { /bin/true|mail -s "$(/bin/date +'%Y%m%d'): $(hostname): ${MOUNT} (${DEV}) ${PERC} full" user@address
done; exit 0
Also please edit your OP and remove the email addresses (wrt spam), TIA.



Code:
function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/ 
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq 
http://wooledge.org/mywiki/BashPitfalls"; }

Last edited by unSpawn; 01-11-2012 at 08:20 PM. Reason: //More *is* more
 
Old 01-12-2012, 05:37 AM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
And : Your script works OK with any shell, except csh.
With the 9 lines, and also with empty lines, 10 (and 11).

bash diskspace.sh : OK
dash diskspace.sh : OK
zsh diskspace.sh : OK
ksh diskspace.sh : OK
( All replies are : 53% / , 39% /home )

.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
line 23 :syntax error unexpected end of file detected nipuniitg Linux - Software 8 11-13-2011 02:12 PM
line 313: syntax error: unexpected end of file bes Linux - Newbie 3 05-02-2010 03:32 AM
-bash: *.sh: line 25: syntax error: unexpected end of file prashanth212 Linux - General 8 04-05-2010 11:52 PM
bash line 74: syntax error: unexpected end of file help? andycol Linux - General 5 09-14-2009 08:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration