Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-28-2011, 01:03 PM   #1
LQ Newbie
Registered: Sep 2011
Posts: 2

Rep: Reputation: Disabled
linux shell question

Hello, i wrote a python script to check wether servers on my remote VPS machine are online.

When they are not online, it means the process could have died, or that the process is stalled ( not responding). When it's not responding, it won't respond to packet i send with python.

When server is not responsive, i run a .sh script with os.system(' process_name path_to_process').

my looks like this:

echo "$1"
echo "$2"

$pid = `pidof -s $1`
if [ $pid -eq ""]
   echo "$1 not found!"
   echo $pid
   kill $pid
screen "$2" 
screen "-d"
basically what i want to do is:
check if the process is alive: if so, kill it.
start server, and detach it from screen and return to python window.

This script gives me all kind of problems:
./home/ line4 =:command not found
There is no screen to be detached.

I'm doing this all using putty on a remote VPS. I have absolutely no idea what i'm doing in the shell script, i just all googled this together. I don't feel like learning ANOTHER scripting language, so that's why i came here to ask.

Last edited by uperate_toor; 09-28-2011 at 01:07 PM.
Old 09-28-2011, 01:09 PM   #2
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Firstly, you don't use the $ sign in assignment statements. Next, there shouldn't be spaces either side of the equals sign. Thirdly, it's more readable if you use $() instead of backticks. So, the offending line should read

pid=$(pidof -s $1)
Old 09-28-2011, 01:20 PM   #3
LQ Newbie
Registered: May 2009
Location: Co. Kerry, Ireland
Distribution: CentOS, Fedora, RedHat, Ubuntu Enterprise Cloud
Posts: 12

Rep: Reputation: Disabled
Originally Posted by uperate_toor View Post
This script gives me all kind of problems:
./home/ line4 =:command not found
There is no screen to be detached.
Please remove the blanks on the left and right side of = .

If you intend to see the result of the shell script inside python (you are using echo BTW) you have to call the script in a very different way from python.

Pipe = os.popen("", "r")
Result =
print Result
You'll need a pipe to read the standard output of the shell script. If you use os.system you could only use commands that don't write to stdout (like cp or killall). IMHO a simple killall would do what you want.

Last edited by Tinkster; 10-02-2011 at 01:30 PM.
Old 09-28-2011, 01:34 PM   #4
LQ Newbie
Registered: Sep 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
now i have os.popen("./home/" + arg1 +" "+ arg2) in python

and this is the
killall "$1"
screen "$2"
problem: doesn't automatically detach from screen, script doesnt exit because it hangs in the screen.
Old 09-28-2011, 05:29 PM   #5
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
Look at the output of "ps -afe". You'll see two columns PID and PPID. PID is the pid of the process on that line, and PPID is the pid of the parent of that process.

In order to run a process which keeps running when you log out, you might like to use the "nohup" command. If you don't use nohup, when you log out, the process you started will receive the hangup signal SIGHUP, and if it is a well-behaved process, it will probably hangup when it gets that signal. So you log out, the process stops.

If you use "nohup", the process won't get the SIGHUP, so it won't hangup. It will instead change its parent pid (PPID) to be 1, which is probably the init process.

So what you might like to try is:

* start the process in the background with nohup
* log out
* log in again and check that the process is still running and has changed its PPID to 1
* make sure the servers are still running.

something like this might work:

nohup server-process &


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
New to linux and have a question about a shell script I'm attempting to write trace_effect Linux - Newbie 9 12-11-2009 01:23 AM
Linux Shell programming question ducka Programming 4 09-01-2003 09:24 AM
linux question about bash, shell ?? albina Linux - General 3 05-15-2002 01:07 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration