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('script.sh process_name path_to_process'). my script.sh looks like this: Code:
echo "$1" 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/script.sh: line4 =:command not found and 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. |
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
Code:
pid=$(pidof -s $1) |
Quote:
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. Quote:
|
Alright,
now i have os.popen("./home/script.sh" + arg1 +" "+ arg2) in python and this is the script.sh Code:
killall "$1" |
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 & |
All times are GMT -5. The time now is 11:37 AM. |