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.

\r. Or possibly the last line is missing a newline. The finalfiwould be a good candidate. List the script usingcat -vet script.sh- \r shows up as^M, newline as$. Cut and paste will probably be removing such characters.sipservers_statuscommand outputting a status value with a trailing CR too.CR LFwhich is Windows-speak for\r\n. You need to remove every occurrence of CR withdos2unix, ortr, or your favourite editor.