maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   shell script question (https://talk.maemo.org/showthread.php?t=91057)

macey 2013-08-17 12:36

shell script question
 
Hello, I am no shell script expert but have been dabbling for some time.
I have a routine that I user for killing selected tasks:-
Code:

for i in `ps aux|grep  "vlc" |grep -v grep | awk '{print $1}' ` ; do
          kill -9 $i
          done

On my N900

Code:

ps aux|grep  "vlc" |grep -v grep
would typically return:-
Code:

19716 user    81648 S    /opt/VideoLAN/bin/vlc -I dummy --volume 120 http://name:password@localhost:9981/stream/channelid/60
Executing the kill code would kill task 19716 successfuly.

If I modify the code in any way to be more selective in killing my vlc task, sometihing like:-
Code:

for i in `ps aux|grep  "vlc -I dummy --volume 120 http://name:password@localhost:9981/stream/channelid" |grep -v grep | awk '{print $1}' ` ; do
          kill -9 $i
          done

Code:

ps aux|grep  "vlc -I dummy --volume 120 http://name:password@localhost:9981/stream/channelid" |grep -v grep
returns:-

Code:

19716 user    81648 S    /opt/VideoLAN/bin/vlc -I dummy --volume 120 http://name:password@localhost:9981/stream/channelid/60
But executing the modified "kill loop" code does not kill task 19716.

Anyone here able to tell me why?
I have changed the code in any number of ways to select just this type of vlc task, using grep "9981*, grep "stream"..... Only grep "vlc" seems to work.
I thought I knew how this code worked, very myserious!:confused::confused

FatPhil 2013-08-17 14:42

Re: shell script question
 
In a rush, but here are some pointers

$ ps | grep '[v]lc'

That grep won't match the grep itself, so no need for the grep -v to remove it

However, the big gun for finding processes, and killing them, are these two:

$ pgrep vlc
$ pkill vlc

I know these commands are enabled on the old R&D images that I'm still running on my old devices, not sure if it's in the released shell.

jackburton 2013-08-17 15:54

Re: shell script question
 
Why kill -9? You should try plain "kill". If the process is responding normally, it should quit gracefully. Only do a "-9" if you intend a "force quit."

There could be something wrong with the more selective grep. You may want to double check that your 'kill' line is even getting executed.
instead of
Code:

kill -9 $i
try:
Code:

echo 'killing '"${i}" >> kill.log && kill "${i}"
to add some logging. If there's nothing in the log, then the grep isn't doing what you want.

Also, be careful with something like "8891*" as this is treated as a regular expression and the "*" is not the same as the "*" in bash, where it's a glob character and not a regular expression meta-character.


All times are GMT. The time now is 08:57.

vBulletin® Version 3.8.8