Results 1 to 4 of 4

Thread: shell script question

  1. #1
    Join Date
    Oct 2007
    Beans
    94

    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 arm linux machine (Nokia 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!
    Last edited by macey; August 17th, 2013 at 01:03 PM.

  2. #2
    Join Date
    Sep 2006
    Beans
    8,623
    Distro
    Ubuntu 14.04 Trusty Tahr

    pgrep

    There's a utility called pgrep. Does that do what you want? Note that there is also an option (-x) for exact matches not just patterns.

    Or are you writing a whole script on principle?

  3. #3
    Join Date
    Oct 2010
    Location
    London
    Beans
    481
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: shell script question

    I had a very similar function in my .bashrc, until I discovered that I could just use the commands 'killall' or 'pgrep'/'pkill'.

    Code:
    pkill -f 'vlc -I dummy --volume 120 http://name:password@localhost:9981/stream/channelid'
    I'm not sure why you command actually breaks, though.
    Please mark your thread as solved if you get a satisfactory solution to your problem.

  4. #4
    Join Date
    Oct 2007
    Beans
    94

    Re: shell script question

    Quote Originally Posted by evilsoup View Post
    I had a very similar function in my .bashrc, until I discovered that I could just use the commands 'killall' or 'pgrep'/'pkill'.

    Code:
    pkill -f 'vlc -I dummy --volume 120 http://name:password@localhost:9981/stream/channelid'
    I'm not sure why you command actually breaks, though.
    That does it , thanks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •