Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a simple script which takes commands to start, stop, restart and return the status of a game server (SA:MP). The site provides the solution for using this command:

./samp03svr &

Which works all well and dandy however when the script executes this it holds and waits for user input (pressing ENTER) which then continues script execution.

I can't seem to find a way to keep the scripts execution without waiting for any user input. I've been searching for about 5 hours now and have tried at least 20 different things including running screen. Running screen worked just doesn't provide the exact thing I am looking for. The script also collects the process ID immediately after like so:

mv ./server_log.txt ./logs/server_$NOW.txt
mv ./mysql_log.txt ./logs/mysql_$NOW.txt
./samp03svr <<< echo &
pid=$!
echo $pid > $pidf
echo -e "The server has been started successfully"

The message that comes up waiting for RETURN is:

Started server on port: 7777, with maxplayers: 30 lanmode is OFF.

The server is running 64-bit Ubuntu 12.04.

Thanks in advance.

share|improve this question
1  
It is not clear. You asking how to automatically press ENTER key? –  c0rp Apr 2 at 6:14
    
I guess that could be one solution but I guess another could be just a way of skipping the command from waiting. –  MrTeddy Apr 2 at 6:46

3 Answers 3

up vote 0 down vote accepted

Because samp03svr outputs text, you need to redirect the output to null

 ./samp03svr > /dev/null 2>&1 &
share|improve this answer

You may try to write a newline (\n) character to the standard input before running the server.

This is an example that write "foo" and pipes it to the std.in of the next command

echo $'foo' | while read x ; do echo $x ; done

So in your case you could do

echo $'\n' | ./samp03svr

Newline quoting example taken from here.

share|improve this answer
    
Thanks! Unfortunately this only puts a linebreak in after the text which appears for the server starting. –  MrTeddy Apr 2 at 7:14

Can you paste this script somewhere, or the part of the script where it is trying to read ENTER key.

Also try this, assuming it waiting for newline:

./samp03svr <<< echo &

share|improve this answer
    
I think the hold is in the samp03svr but that file is complied since it is the server binary. I've updated the post with a larger snippet of the start up code in my script and the exact message its holding on. –  MrTeddy Apr 2 at 15:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.