LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-04-2016, 08:42 PM   #1
ntbluez
LQ Newbie
 
Registered: Nov 2015
Posts: 21

Rep: Reputation: Disabled
Syntax Error: Unexpected End of File


Appreciate you help...
I do not know why I am getting this error while running a script.
Any ideas how to resolve my problem?

[xunil@labsrv1 DF]$ ./1.sh
./1.sh: line 12: ssyntax error: unexpected end of file

for SERVER in 'cat server-list'

do
ssh xunil@192.168.184.129 df -h | grep -vE '^Filesystem|cdrom' | awk '{print $5 " " $1}' | while read output;
do
echo $output
usep=$(echo $output | awk '{print $1}' | cut -d% -f1)
partition=$(echo $output | awk '{print $2}')
if [ $usep -ge 10 ]; then
echo "Running out of space "$partition $usep%" on $(hostname) as on $(date)" >> results.log
fi
done
 
Old 02-04-2016, 10:02 PM   #2
Habitual
LQ 5k Club
 
Registered: Jan 2011
Location: Nowhere near you, thank God.
Distribution: High Sierra
Posts: 8,598
Blog Entries: 15

Rep: Reputation: Disabled
Is that 1.sh b/c I don't see but 10 lines?
 
Old 02-04-2016, 10:07 PM   #3
af7567
Member
 
Registered: Nov 2012
Posts: 204

Rep: Reputation: 67
You have 2 do's but only 1 done. Maybe you need another done at the end.
 
Old 02-04-2016, 10:28 PM   #4
ntbluez
LQ Newbie
 
Registered: Nov 2015
Posts: 21

Original Poster
Rep: Reputation: Disabled
Not sure if 2 "do" are needed (new at this stuff, scripting) & also, I know the error always says a line more or so than what I truly have in script.
Can't figure it out - I manually created script via vi and also tried nano while inside of linux. Not sure what's up.

So, need help to resolve this syntax error: unexpected at end of file...
 
Old 02-04-2016, 10:45 PM   #5
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 6,155

Rep: Reputation: Disabled
Try adding newline at the end.
 
Old 02-05-2016, 01:49 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,905

Rep: Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921
Quote:
Originally Posted by ntbluez View Post
So, need help to resolve this syntax error: unexpected at end of file...
It was already told to you. You have two do statements and only one done. The interpreter is trying to find the other one, but it found only the unexpected end of the file.
That's all.

furthermore please use [code]here comes your script[/code] to keep formatting.

Last edited by pan64; 02-05-2016 at 01:51 AM.
 
Old 02-05-2016, 03:18 AM   #7
MrTux
Member
 
Registered: Dec 2015
Posts: 131

Rep: Reputation: Disabled
a done is missing
 
Old 02-06-2016, 05:21 AM   #8
tramsch
LQ Newbie
 
Registered: May 2014
Distribution: RHEL, CentOS, Mint, Debian
Posts: 20

Rep: Reputation: 1
Hi ntbluez,

indentation helps a lot...

I also added "-n" in your ssh-command, preventing ssh to read from stdin and breaking your loop.
Additionally , I think the "|" in your grep needs to be escaped.

Code:
for SERVER in 'cat server-list'
do
  ssh -n xunil@192.168.184.129 df -h | grep -vE '^Filesystem\|cdrom' | awk '{print $5 " " $1}' | while read output;
  do
    echo $output
    usep=$(echo $output | awk '{print $1}' | cut -d% -f1)
    partition=$(echo $output | awk '{print $2}')
    if [ $usep -ge 10 ]; then
      echo "Running out of space "$partition $usep%" on $(hostname) as on $(date)" >> results.log
    fi
  done
done
As a side note, you try to monitor diskspace, have you thought about things like nagios, icinga or monit?
Or maybe just the nagios plugins and the nrpe daemon might already accomplish what you are trying to achieve.

BR
Florian
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] syntax error: unexpected end of file Revenge7 Linux - Newbie 2 03-19-2015 05:35 AM
Syntax Error: Unexpected File End Ripowal Programming 13 09-20-2011 01:44 AM
[SOLVED] syntax error: unexpected end of file adidoosh100 Programming 14 08-08-2010 01:44 AM
why i get syntax error: unexpected end of file ?? freephys Linux - Newbie 3 06-24-2010 10:03 AM
syntax error: unexpected end of file ygdrazil Linux - Newbie 3 07-23-2009 06:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:43 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration