Technical question regarding Cron jobs
#1
So we run a Teamspeak2 server here at the Lounge. Works great. But when Something Goes Wrong™ and the server gets bounced, or there's maintenance, whatever, the Teamspeak2 server goes down.

In order for it to come back up, the file tsserver2.pid needs to be deleted in the tss2_rc2 directory and the teamspeak2-server_startscript file executed. I can do this manually, no problem.

I've set up a cron job, however, that should do this automatically, and run every 15 minutes. It checks to see if a Teamspeak2 process is running, and if not, delete the tsserver2.pid file and restart Teamspeak2.

The cron job runs this file:

Code:
#!/bin/sh
#
# TeamSpeak Cron Job
# Author: Chris Childers
# E-Mail: Chris@darkstarllc.com
# Address: http://www.darkstarllc.com
#

### Set your default TS Root Directory
tsdir="/tss2_rc2"

### Set your TS Binary Name
tsbin="server_linux"

### Set your TS Pid File
tspid="tsserver2.pid"

########## you probably don't need to change anything below here ##########

cd $tsdir

# is there a pid file?
if test -r $tspid
then
  # there is a pid file -- is it current?
  pid=`cat $tspid`
  if `kill -CHLD $pid >/dev/null 2>&1`
  then
    echo "TeamSpeak is currently running...."
    exit 0
  fi
  echo ""
  echo "Stale $tspid file, erasing..."
  echo "Attempting to Restart TeamSpeak"
  rm -f $tspid
  ./$tsbin -PID=$tspid &
else
echo "$tspid appears to be missing. Attempting to Restart TeamSpeak"
./$tsbin -PID=$tspid
fi

If I execute this manually, I receive:

Code:
: bad interpreter: No such file or directory

Thing is, if I go to /bin, sh is right there and can be run as an interpreter just fine. So can bash. But if the file being executed by the cron job goes to run it, I get that error.

Yes, I'm a linux newb. WTF is wrong here?

-Bolty
Quote:Considering the mods here are generally liberals who seem to have a soft spot for fascism and white supremacy (despite them saying otherwise), me being perma-banned at some point is probably not out of the question.
Reply
#2
There are a number of things to check.

#1 issue would be to look for a dos2unix file convert tool if you think there might be a carriage return translation issue moving a dos file onto unix.
”There are more things in heaven and earth, Horatio, Than are dreamt of in your philosophy." - Hamlet (1.5.167-8), Hamlet to Horatio.

[Image: yVR5oE.png][Image: VKQ0KLG.png]

Reply
#3
What comes to mind is to make sure the case is correct. Many a times I've been jerked around because I spelled something "aabb" instead of "AaBb." The only other thing I can think of would be that you need to be more specific with tha path or something like that.

Then again, I probably know even less about Linux than you do, so I might be going in the absolute wrong direction.
Alea Jacta Est - Caesar
Guild Wars account: Lurker Wyrm
Reply
#4
Quote:#1 issue would be to look for a dos2unix file convert tool if you think there might be a carriage return translation issue moving a dos file onto unix.
Oh yes. I found this out when searching the web for info, and used vi to verify that there were no ^M's or anything hidden in the file. Doesn't seem to be any CRLF problems.

-Bolty
Quote:Considering the mods here are generally liberals who seem to have a soft spot for fascism and white supremacy (despite them saying otherwise), me being perma-banned at some point is probably not out of the question.
Reply
#5
Quote:Oh yes. I found this out when searching the web for info, and used vi to verify that there were no ^M's or anything hidden in the file. Doesn't seem to be any CRLF problems.

-Bolty

Modern versions of vi (read -- the vi with linux which is really vim in a reduced mode) are not the best test for this, as they understand how to deal with DOS text files and will hide the ^M's from you.
Reply
#6
Quote:If I execute this manually, I receive:
Code:
: bad interpreter: No such file or directory

Is this the only output you receive? Or do you get the echos from early in the script when you run manually?

It is possible that the actual execution of the teamspeak server script itself could be giving that error.
Reply
#7
Quote:Modern versions of vi (read -- the vi with linux which is really vim in a reduced mode) are not the best test for this, as they understand how to deal with DOS text files and will hide the ^M's from you.
Turns out you're right. Someone PM'ed me with the command:

Code:
head -1 <scriptname> | od -c | head -1

Which I ran, and found that there was a \r in the first line:

Code:
-bash-2.05b$ head -1 tschk.sh | od -c | head -1
0000000&nbsp;&nbsp; #&nbsp;&nbsp; !&nbsp;&nbsp; /&nbsp;&nbsp; b&nbsp;&nbsp; i&nbsp;&nbsp; n&nbsp;&nbsp; /&nbsp;&nbsp; s&nbsp;&nbsp; h&nbsp;&nbsp;\r&nbsp;&nbsp;\n

This never showed in vi. Bleh. I used an online Dos2Unix converter to strip the \r and it works now.

Thanks guys!

-Bolty
Quote:Considering the mods here are generally liberals who seem to have a soft spot for fascism and white supremacy (despite them saying otherwise), me being perma-banned at some point is probably not out of the question.
Reply
#8
Bolty, if you keep looking at crOn you are going to get hairy palms and go blind.
All alone, or in twos,
The ones who really love you
Walk up and down outside the wall.
Some hand in hand
And some gathered together in bands.
The bleeding hearts and artists
Make their stand.

And when they've given you their all
Some stagger and fall, after all it's not easy
Banging your heart against some mad buggers wall.

"Isn't this where...."
Reply
#9
Quote:This never showed in vi. Bleh. I used an online Dos2Unix converter to strip the \r and it works now.

Thanks guys!

-Bolty

Your vim must not be configured right.:) You can configure it to announce the file format when it loads, or you can query it once vim is open. Once you've opened the file, do ":set fileformat?". The question mark indicates you want to know the value of the option, rather than actually set it. Vim will respond with " fileformat=dos" or " fileformat=unix" as appropriate. You can also use ":set fileformat=unix" to switch the line ending type. Many Linux systems also ship with dos2unix for fixing this on-system (without needing to go online).

Spurious carriage returns are very common when you upload files from systems with broken line ending conventions (most notably, Microsoft Windows suffers from this). Old Macintoshes tended to use carriage returns without line feeds; this may have been fixed with OSX since it uses a BSD userland now.

Incidentally, that bash looks a bit old. What do you get when you run "uname -a"? I'd expect bash 3.00 on a new distribution. If you're running something older, be sure the admin is keeping up to date on kernel patches. There've been some very embarassing privilege escalation bugs recently.
Reply
#10
Well you shouldn't be using a DOS based file as TeamSpeak has a GNU/Linux version available. Aside from that, check the permissions as was stated lower in the thread. If for whatever reason the normal user you have (you have one right?) doesn't have permission that is your problem. But also check in on the TeamSpeak file permissions and the script you just wrote. Because it is possible that you wrote that script, but only root can run it, but you may be trying to run it under your normal user that isn't root.

An excellent reference for all things GNU/Linux is www.linuxquestions.org The forums are full of gurus and the people are very helpful in my experience. Good luck!
WWBBD?
Reply
#11
Quote:...and it works now.

Stop you geeks! :-)
”There are more things in heaven and earth, Horatio, Than are dreamt of in your philosophy." - Hamlet (1.5.167-8), Hamlet to Horatio.

[Image: yVR5oE.png][Image: VKQ0KLG.png]

Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)