You are not logged in.

#1 2011-02-16 08:56:50

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Bash script to terminated upon logout,

Hi all,

I have created a bash script - which start recording a camera device for security purpose, but I need the script to finish when the security user is logging out.

Any idea on how to do that?

Offline

#2 2011-02-16 09:08:37

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Bash script to terminated upon logout,

Isn't this how the scripts work by default?
http://www.xaprb.com/blog/2008/08/01/ho … u-log-out/

Last edited by karol (2011-02-16 09:11:24)

Offline

#3 2011-02-16 09:34:01

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: Bash script to terminated upon logout,

Before regarding any answers given, please define what the security user is
logging out from. A shell? A graphical environment? Some program? The answers
can differ a lot based on that information.

Offline

#4 2011-02-16 09:43:14

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Bash script to terminated upon logout,

sweetthdevil wrote:

Hi all,

I have created a bash script - which start recording a camera device for security purpose, but I need the script to finish when the security user is logging out.

Any idea on how to do that?

If you use xdm for the login manager, I see from the man page that the Xreset (/etc/X11/xdm/Xreset) script is run. So you could kill the script from there. I suppose something similar must exist for other display manager.

Offline

#5 2011-02-16 22:42:33

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Bash script to terminated upon logout,

The user is logging out of it's graphical session (gnome) using gdm.

So the computer stay up and running but the "security" user is logged out so the bash stop, ideally.

Many thanks for the quick replies

Offline

#6 2011-02-17 07:52:29

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: Bash script to terminated upon logout,

sweetthdevil wrote:

The user is logging out of it's graphical session (gnome) using gdm.

So the computer stay up and running but the "security" user is logged out so the bash stop, ideally.

Many thanks for the quick replies

I figured it'd be something like that. If you were using a .xinitrc/.xsession
file to start the security user's graphical environment, you could just omit the
often used 'exec' before the window manager command and call your script right
afterwards.

Unfortunately, gnome doesn't use these files and I don't know what exactly it
does use, so I'll pass this question on to my fellow Archers amongst whom there's
surely one to help you smile

Offline

#7 2011-02-17 08:17:44

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Bash script to terminated upon logout,

Have you read my post about xdm? I do not use gdm but I see there http://superuser.com/questions/65460/cr … -for-linux (after a few minutes googling) that gdm use /etc/gdm/PostSession/Default after the session (similar to the Xreset for xdm). So just kill the script from there (I assume you know how to write bash scripts, send a signal with kill (or pkill) and depending on your script you may have have to intercept the signal for proper termination of you recording script).

Offline

#8 2011-02-17 08:55:46

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Bash script to terminated upon logout,

Yes I had read your post - but it was late and I after a long train journey I just reply to the quick question.

Now I have fixed it, adding pkill mencoder to the /etc/gdm/PostSession/Default and it's done!

Many thanks,

Offline

#9 2011-02-25 13:19:48

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Bash script to terminated upon logout,

Hi again,

This is working very well, but I have another issue - I would like to be able to "pkill mencoder" when shutting down the pc (using gnome menus) where is the script executed when shutting down or rebooting?

Many thanks

Offline

#10 2011-02-25 14:01:22

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Bash script to terminated upon logout,

sweetthdevil wrote:

Hi again,

This is working very well, but I have another issue - I would like to be able to "pkill mencoder" when shutting down the pc (using gnome menus) where is the script executed when shutting down or rebooting?

Many thanks

/etc/rc.shutdown

Offline

#11 2011-03-01 11:43:54

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Bash script to terminated upon logout,

Hi again,

sorry it took some time but I haven't had the time to look yet,

Back to the topic, I added the "pkill mencoder" at the begining of the file but it doesn't seem to work (because when shutting down the pc, the avi file created is broken - the index)

Any suggestion?

Offline

#12 2011-03-04 00:58:13

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Bash script to terminated upon logout,

sweetthdevil wrote:

Hi again,

sorry it took some time but I haven't had the time to look yet,

Back to the topic, I added the "pkill mencoder" at the begining of the file but it doesn't seem to work (because when shutting down the pc, the avi file created is broken - the index)

Any suggestion?

Difficult to say like this. If you kill mencoder by hand (not with the logout script); does this work properly? Maybe you have to wait that men,coder actualy exit before continuing:

PID=$(grep mencoder)
kill $PID
wait $PID

(work only if there is a single mencoder process).

But how did you start mencoder? (o processes receive a HUP signal if the terminal from which it has been opened is closed).

Last edited by olive (2011-03-04 00:58:30)

Offline

Board footer

Powered by FluxBB