Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6761565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:12:29+00:00 2026-05-26T14:12:29+00:00

I have the following script #!/bin/sh if [cat stream_should_be_running.txt == ‘true’]; then #file will

  • 0

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:

  1. why am i pulling the syntax error
  2. 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 , and cat stream_should_be_running.txt all 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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:12:30+00:00Added an answer on May 26, 2026 at 2:12 pm

    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”.

    #!/bin/sh
    PID=$(pidof -s tracker_stream);
    if [ $(cat stream_should_be_running.txt) = "true"]; then #file will either contain true or false
        if [ -z $PID ]; then # check if stream is currently NOT running
            /usr/local/bin/python2.7 ~/webapps/dashboard/fbadmin/manage.py tracker_stream; # restart stream
            exit 0;
        fi
    fi
    

    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 a M, it’s a end of line character.

    You could open your file with vim -b to check if you see any of those characters.
    Then type:

    :%s/^V^M//g 
    

    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”?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following bash script: #!/bin/bash FILE=p.txt while read line; do export http_proxy=http://$line
I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
I have the following script #!/usr/bin/Rscript print (shebang works) in a file called shebang.r.
I am trying a simple shell script like the following: #!/bin/bash up_cap=$( cat result.txt
Say I have the following Bash script stored in the file foo.sh : #!/bin/bash
I have the following script: cat > /tmp/script.sh <<EndOfScript #!/bin/sh ulimit -n 8192 run_app
So I have the following script (just a test) #!/bin/bash for file in *
I have a following bash script: 1 #!/bin/bash 2 query='query= SELECT * WHERE {
I have the following bash script, we can call it script1.sh : #!/bin/bash exec
I have to maintain the following Perl script: #!/usr/bin/perl -w die Usage: $0 <file1>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.