You are not logged in.

#1 2009-03-10 20:14:19

colbert
Member
Registered: 2007-12-16
Posts: 809

Script help

I am trying to make a simple little script that will check for mythfrontend with pidof and then kill it if the process exists (it rarely but time to time freezes). This is for a Mythbox for the family room and I intend to bind the script execution to a remote button via lirc so it can be done instantly, but it is not working correctly:

#! /bin/bash
if pidof mythfrontend ; then
 zenity --notification --text="Mythfrontend process successfully killed :)" && kill -s 9 $1
else
# echo "Mythfrontend not running" && 
 exit
fi

I tested and I got this output:

~/scripts/myth > ./kill-frozen-fe 
21369
Xlib:  extension "Generic Event Extension" missing on display ":0.0".
Xlib:  extension "Generic Event Extension" missing on display ":0.0".
Xlib:  extension "Generic Event Extension" missing on display ":0.0".
Xlib:  extension "Generic Event Extension" missing on display ":0.0".
Xlib:  extension "Generic Event Extension" missing on display ":0.0".
Xlib:  extension "Generic Event Extension" missing on display ":0.0".

And mythfrontend was not killed. (And I have seen that xlib line before and other scripts/commands have worked fine despite it.)

TIA for any help smile

Last edited by colbert (2009-03-10 20:15:34)

Offline

#2 2009-03-10 20:18:19

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Script help

the Xlib errors are meaningless but i think they prevent you're kill command because zenity is reporting errors thus && will never execute the kill.

reverse the statement with kill ... && zenety ... 2>/dev/null

that should kill myth, then [if successful] display the message and send the meaningless Xlib errors to the /dev/null abyss.

hope it works.

Offline

#3 2009-03-10 20:22:56

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: Script help

Thanks brisbin33, I have tried the line like this:

 kill -s 9 $1 && zenity --notification --text="Mythfrontend process successfully killed :)" 2>/dev/null

But it keeps showing this:

~/scripts/myth > ./kill-frozen-fe 
21449
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
~/scripts/myth >

If I take out the zenity line and try this:

 kill -s 9 $1 2>/dev/null

Then it shows the process ID with that "kill: usage.." etc. line disappearing to the /dev/null. I think it's the "kill -s 9 $1" part not going right, I tried $2 and $0 but no go. Strange because in my .bashrc I have "k9" alias for "kill -s 9 $1" but here not working sad

Offline

#4 2009-03-10 20:26:31

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Script help

i'm a little confused... they way i would do it is this:

PID=`pidof mythfrontend`
if [ ! -z "$PID" ]; then
   kill -s 9 $PID && zenity ... 2>/dev/null
fi

right?

edit, slight difference... i /think/ [ -e $thing ] is the same as [ ! -z $thing ], but i know this way works.

Last edited by brisbin33 (2009-03-10 20:29:08)

Offline

#5 2009-03-10 20:27:16

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Script help

$1 after kill should be $(pidof mythfrontend)

Or rather,

#! /bin/bash
pid=$(pidof mythfrontend)
if [ $? = 0 ] ; then
 zenity --notification --text="Mythfrontend process successfully killed :)" && kill -s 9 $pid
else
# echo "Mythfrontend not running" && 
 exit
fi

And the xlib stuff is just messages and does not do anything to the && statement.

Offline

#6 2009-03-10 20:33:31

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: Script help

Thanks very much fellas. Procyon that worked! Brisbin33 I tried that way of your post but it did not kill the process, but gave no errors.

Thanks a lot for the help guys smile

Offline

Board footer

Powered by FluxBB