I have the following script
#!/bin/sh
if [cat stream_should_be_running.txt == 'true']; then #file will either contain true or false
if [ps ax|grep -v grep|grep tracker_stream]; then # check if stream is currently running
exit 0
else
/usr/local/bin/python2.7 ~/webapps/dashboard/fbadmin/manage.py tracker_stream; # restart stream
exit 0
else
exit 0
fi
This script should check if a daemon script is suppose to be running. If it is suppose to be running then it checks to see if the script is running and restarts it if it isn’t. Currently I get syntax error: unexpected end of file when I try to running the file manually.
So two questions:
- why am i pulling the syntax error
- outside of this should this script run properly?
Thanks
EDIT:
here is an updated version of the script and a few notes:
#!/bin/sh
set -vx; # turn on shell debugging
if [[ "$(cat stream_should_be_running.txt)" == "true" ]]; then
if [ ps ax|grep -v grep|grep -q tracker_stream ]; then
exit 0
else
/usr/local/bin/python2.7 ~/webapps/dashboard/fbadmin/manage.py tracker_stream;
exit 0
fi
else
exit 0
fi
to note:
- vim marks
$(...)as a syntax error ( i don’t know if that matters) ps ax|grep -v grep|grep -q tracker_stream,ps ax|grep -v grep|grep tracker_stream, andcat stream_should_be_running.txtall execute properly from the command line
EDIT 2:
shell debugging gives the error
$ sh stream_checker.sh
+ $'\r'
: command not foundline 3:
if [[ "$(cat stream_should_be_running.txt)" == "true" ]]; then
echo 'test';
if [ ps ax|grep -v grep|grep -q tracker_stream ]; then
exit 0
else
/usr/local/bin/python2.7 ~/webapps/dashboard/fbadmin/manage.py tracker_stream;
exit 0
fi
else
exit 0
fi
stream_checker.sh: line 15: syntax error: unexpected end of file
so the only things that come before where the + $'\r' is returns are #!/bin/sh and set -vx.
This is running on a linux system. The my local machine is osx lion and the live machine is a linux server on webfaction.
1) I think I got it…
I used the ‘-s’ switch in pidof to only get one result.
The ‘-z’ switch means “return true if the string is empty”.
EDIT: From the last note you posted it looks like you might have a Ctrl-M char
(^M), somewhere on your file.It’s not merely a
^followed by aM, it’s a end of line character.You could open your file with
vim -bto check if you see any of those characters.Then type:
That command reads like “match all (^M) chars and substitute them with void”.
In short it will remove all (^M) chars from your file.
The (^V^M) bit means that you have to hit CTRL-V CTRL-M, in order to insert the (^M) char.
2) what exactly do you mean by “outside of this”?