Results 1 to 9 of 9
Dear reader,
Im pretty new with Linux and this forum, so if I post this on the wrong section; please correct me.
atm I use a centos VPS with 1gb ...
- 09-24-2010 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
Screen start/stop script with a name?
Dear reader,
Im pretty new with Linux and this forum, so if I post this on the wrong section; please correct me.
atm I use a centos VPS with 1gb memory and enough space and brandwidth (if this info is off any use).
What I want to achieve is that I can start and quit a process that is running in a screen, with using a script.
Like start.sh that does "screen serverapp1"
and stop.sh that does "kill serverapp1"
I already tried something like that, but it didnt work. The kill command only works with process ID's and that one is variable.
Kinds,
GuidoLast edited by zondvloed; 09-24-2010 at 11:24 AM.
- 09-24-2010 #2
Try with pkill or killall.
- 09-24-2010 #3Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
[servercod4001@datacenter-196 ~]$ screen -ls
There is a screen on:
11343.servercod4001 (Detached)
1 Socket in /var/run/screen/S-servercod4001.
[servercod4001@datacenter-196 ~]$ killall -u servercod4001
/proc is empty (not mounted ?)
[servercod4001@datacenter-196 ~]$ killall servercod4001
/proc is empty (not mounted ?)
- 09-24-2010 #4
Welcome to the forums zondvloed,
It seems your VPS isn't a full environment, or you don't have the right permissions. I could be wrong, but I think tools relying on /proc to be mounted wont work, alas.
That said, screen stores it's pids like this:
So getting the PID is just a matter of prying it out of the named pipe:
Originally Posted by zondvloed
Note: "tached" will match both Attached and Detached. It'll also error when there are multiple sessions. You could do aCode:kill `screen -ls | grep "tached" | cut -d'.' -f1`
Code:for i in `screen -ls | grep "tached" | cut -d'.' -f1` ; do kill $i ; done
___
That is, assuming `pidof` wont work. Otherwise:
Would suffice. Worth a try.Code:kill `pidof processname`
Can't tell an OS by it's GUI
- 09-24-2010 #5Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
thank you very much
The first one works, so my problem is solved.
But now for the educational part;
what does "tached" do? what is it?
and what does pidof do?
- 09-24-2010 #6Nothing. It's a passive and fully arbitrary pattern, but I don't think I'm much clearer now
Originally Posted by zondvloed 
I believe 'grep' was called thus to abbreviate 'global/regular expression/pattern' or something similar. Basically, you send it a stream of data and let grep pick out the parts that you want. So it goes like this:
gives the output:Code:screen -ls
But we're only interested in line 2. So we pluck that out. There's thousands of ways to do that. The one I chose was to point grep at one of it's distinctive features. Well, I don't know the name of the session, and I don't know the pid, but I do know it's state can be either 'Attached' or 'Detached', and what binds these words is that they both have 'tached' in their name. Any recognizable and unique pattern in the string could have worked.Code:There is a screen on: 11343.servercod4001 (Detached) 1 Socket in /var/run/screen/S-servercod4001.
Gives the output:Code:screen -ls | grep "tached"
And I only need the first number, so using the period '.' as a delimiter:Code:11343.servercod4001 (Detached)
Gives the output:Code:screen -ls | grep "tached" | cut -d'.' -f1
Now I feed that to kill by putting it in `` marks (not to be confused with the single quote ' )Code:11343
is expanded by the shell and interpreted:Code:kill `screen -ls | grep "tached" | cut -d'.' -f1`
Code:kill 11343
pidof does what it's name implies. It gets you the 'pid of' a process.
Originally Posted by zondvloed
You would be helped if the man pages are installed on your VPS
Try `man commandname` such as, indeed, `man pidof` or `man grep`. Other wise things like `grep --help` should give a short version of the options.
And more about using | ; ` & " $ \ > and other goodies in the Advanced Bash-Scripting GuideCan't tell an OS by it's GUI
- 09-24-2010 #7Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
thank you very much for your kindness and help
Yes, but most off the time I dont understand the manual without an example though it was lazy off me not to google it; sorry.
pidof only works for the root, could I implement it for my selfmade user?
- 09-24-2010 #8It appears your regular user doesn't have /sbin in it's path. I hadn't thought of it, because I always put /sbin /usr/sbin and /usr/local/sbin in my users path... that way your 'command not found' gets upgraded to a much more decisive sounding 'permission denied' when you're doing things you're not supposed to. But pidof will work...
Originally Posted by zondvloed
Anyway, when you're scripting it's always good to specify the full path name:
Code:/sbin/pidof
Then I'll leave you this as an excercize
Originally Posted by zondvloed
Can't tell an OS by it's GUI
- 09-24-2010 #9Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
ah jeah, the /proc dir was still on 550, I putted it on 555; since Im the only person who gets there and reading and executing is not too bad to allow there ^^
now /sbin/pidof; works
thanks!


Reply With Quote
