Skip to main content
3 of 4
added 64 characters in body; edited tags
Vlastimil Burián
  • 31.3k
  • 66
  • 211
  • 358

sh script won't run, (unexpected end of file) but the individual lines execute fine

Below is what I'm attempting to run on my remote machine, and I'm getting 'Unexpected end of file'.

However, if i take the lines and paste them into the CLI, it executes normally.

# if [ -f running.script ] ; then echo 'Script already running.'
> else echo 'Script not running.' ; touch running.script
<ervers_status | awk 'NR==1 {print $3}' | tr -d '\r')
<ervers_status | awk 'NR==2 {print $3}' | tr -d '\r')
> if [ "$sip1" = 0 ] ; then echo "Sip Server 1 UP" ; fi
> if [ "$sip1" = 1 ] ; then echo "Sip Server 1 DOWN" ; fi
> if [ "$sip1" = 2 ] ; then echo "Sip Server 1 IDLE" ; fi
> if [ "$sip2" = 0 ] ; then echo "Sip Server 2 UP" ; fi
> if [ "$sip2" = 1 ] ; then echo "Sip Server 2 DOWN" ; fi
> if [ "$sip2" = 2 ] ; then echo "Sip Server 2 IDLE" ; fi
> rm running.script
> fi
Script not running.
Sip Server 1 UP
Sip Server 2 IDLE
#sh script.sh
script.sh: line 14: syntax error: unexpected end of file
# cat script.sh
#!/bin/sh
if [ -f running.script ] ; then echo 'Script already running.'
else echo 'Script not running.' ; touch running.script
    sip1=$(cat /var/mand/sipservers_status | awk 'NR==1 {print $3}' | tr -d '\r')
    sip2=$(cat /var/mand/sipservers_status | awk 'NR==2 {print $3}' | tr -d '\r')
    if [ "$sip1" = 0 ] ; then echo "Sip Server 1 UP" ; fi
    if [ "$sip1" = 1 ] ; then echo "Sip Server 1 DOWN" ; fi
    if [ "$sip1" = 2 ] ; then echo "Sip Server 1 IDLE" ; fi
    if [ "$sip2" = 0 ] ; then echo "Sip Server 2 UP" ; fi
    if [ "$sip2" = 1 ] ; then echo "Sip Server 2 DOWN" ; fi
    if [ "$sip2" = 2 ] ; then echo "Sip Server 2 IDLE" ; fi
    rm running.script
fi
#

I've included the below capture of my NP++ showing exactly what's in the script.

enter image description here