LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-06-2016, 02:02 AM   #1
Steven_G
Member
 
Registered: Dec 2015
Location: Western US
Distribution: Home spun
Posts: 142

Rep: Reputation: 67
Execute CLI argument on firefox shutdown


Google is not my friend tonight, I keep returning a bunch of irrelevant junk no matter how I format the query.

I think what I'm trying to do is fairly simple, or at least the idea is: When firefox closes I want to run a shell command.

I'm looking for the easiest way to do this. An addon would be fine. But I can't find one.

My scripting skills are rudimentary. I now how to set up things to run shell commands on system or program start. But no idea how to execute a function on program close.

Any help greatly appreciated.

Thankx.

Last edited by Steven_G; 01-06-2016 at 03:18 AM.
 
Old 01-06-2016, 02:18 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Well, the simplest way would be to create a script wrapper as simple as that:

Code:
firefox
echo "FF has shut down!" > ~/file.txt
The second line is just an arbitrary command. You could give this script exec rights and run it instead of firefox.

Does this make sense?
 
1 members found this post helpful.
Old 01-06-2016, 03:18 AM   #3
Steven_G
Member
 
Registered: Dec 2015
Location: Western US
Distribution: Home spun
Posts: 142

Original Poster
Rep: Reputation: 67
Quote:
Originally Posted by sycamorex View Post
Does this make sense?
No. You just surpassed my skill level. Got any links to any tuts on building a "script wrapper"? I've never even heard of them.
 
Old 01-06-2016, 03:26 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
a wrapper script is just a normal shell script where you invoke the original command and also you will be able to prepare things before and do anything after.
So that wrapper script will start firefox and do something if firefox closed. And you need to start your wrapper script instead of firefox.
 
1 members found this post helpful.
Old 01-06-2016, 04:16 AM   #5
Steven_G
Member
 
Registered: Dec 2015
Location: Western US
Distribution: Home spun
Posts: 142

Original Poster
Rep: Reputation: 67
Quote:
Originally Posted by pan64 View Post
a wrapper script is just a normal shell script where you invoke the original command and also you will be able to prepare things before and do anything after.
So that wrapper script will start firefox and do something if firefox closed. And you need to start your wrapper script instead of firefox.
Thankx for the clarification. I chewed on it while working on some other stuff and came to pretty much that conclusion.

I'm running a hacked up version of FF dev in one of my remote machines.

They borked clean on close. It spawns an infinite restart loop due to a .js error. I did some minimum digging, decided it was over my skill level and filed a bug report.

But I still want to clean on close. So I want to run bleach bit as a user on close.

(And this post is as much to work it out before I do it as is it to make sure I have it right and understand what's going on.)

The short cut command in my start menu to run it is:

Code:
/home/user/folder/firefox
So I would change that to:

Code:
/home/user/script.sh
And the script would be:
Code:
/home/user/folder/firefox
xfce4-terminal -e "bash -c 'bleachbit -c firefox.* chromium.history;$SHELL'"
And b/c things run in a logical order and the second command can't run until after the first one is completed then the effect would be to have the clean up command run on FF close.

Right?
 
Old 01-06-2016, 04:22 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
yes, but I do not know why do you run xfce4-terminal. Probably
Code:
/home/user/folder/firefox
bleachbit -c firefox.* chromium.history;$SHELL
would be enough (I do not know this bleachbit, so I'm not really sure about that)
 
1 members found this post helpful.
Old 01-06-2016, 04:38 AM   #7
Steven_G
Member
 
Registered: Dec 2015
Location: Western US
Distribution: Home spun
Posts: 142

Original Poster
Rep: Reputation: 67
Quote:
Originally Posted by pan64 View Post
yes, but I do not know why do you run xfce4-terminal. Probably
Code:
/home/user/folder/firefox
bleachbit -c firefox.* chromium.history;$SHELL
would be enough (I do not know this bleachbit, so I'm not really sure about that)
B/c I'm paranoid and I want to see it run instead of having to dig through logs to make sure it ran and my way spawns a terminal and lets me watch it run.

I just tested it.

It works.

Now I just need to add whatever parameter is needed to get the terminal to close after the command runs. (Googling)
 
Old 01-06-2016, 05:59 AM   #8
Steven_G
Member
 
Registered: Dec 2015
Location: Western US
Distribution: Home spun
Posts: 142

Original Poster
Rep: Reputation: 67
OK, I give up for the night.

I've tried tons of stuff from the web and no matter what I do I can't get this stupid terminal instance to close after running the script.

Most everything I've found on the web is some variation of the suggestions here.

And I can't any of them to work.

Any ideas how to get the terminal to close after this runs?
 
Old 01-06-2016, 06:03 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by Steven_G View Post
Now I just need to add whatever parameter is needed to get the terminal to close after the command runs. (Googling)
That should be the default, see man page and option -H http://manpages.ubuntu.com/manpages/...erminal.1.html
 
1 members found this post helpful.
Old 01-06-2016, 12:22 PM   #10
Steven_G
Member
 
Registered: Dec 2015
Location: Western US
Distribution: Home spun
Posts: 142

Original Poster
Rep: Reputation: 67
Quote:
Originally Posted by pan64 View Post
That should be the default
It's not. The script runs and the terminal stays open.

Quote:
Originally Posted by pan64 View Post
I don't see any variables in there to pass a close command to it.

I've tried dozens of variations, too many to list here.

But I've tried appending exit to the end of the script itself and to the end of the last argument. I've tried spawning the terminal with nohup and disowning it. I've tried directly passing an argument to bash to close the xfce4-terminal. And on and on and on. None of it works.

I can't get the stupid thing to close after run.

Suggestions appreciated.
 
Old 01-06-2016, 12:26 PM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
I still think that is the default. The reason it was not closed is (I think) there is something still using it. Try pstree to find it
 
1 members found this post helpful.
Old 01-06-2016, 02:19 PM   #12
Steven_G
Member
 
Registered: Dec 2015
Location: Western US
Distribution: Home spun
Posts: 142

Original Poster
Rep: Reputation: 67
The appropriate section of pstree

Code:
├─sh───xfce4-terminal─┬─bash───bash
        │                     ├─gnome-pty-helpe
        │                     ├─{gdbus}
        │                     ├─{gmain}
        │                     └─{pool}
I know it's a child process and I've tried calling and killing the $PPID variable, but I can't figure out how to make that work either.
 
Old 01-06-2016, 04:44 PM   #13
Steven_G
Member
 
Registered: Dec 2015
Location: Western US
Distribution: Home spun
Posts: 142

Original Poster
Rep: Reputation: 67
I'm making some progress, but not much.

I have gnome and xfce4 on the machine.

If I open the gnome-terminal and run
Code:
pidof xfce4-terminal
then I get the current pid and can kill it with
Code:
pkill -TERM -P <current pid>
But, that's only good for one shot b/c the pid changes on ever spawn. (Tested)

So how do I call pidof xfce4-terminal as a variable which I can then kill?
 
Old 01-06-2016, 05:29 PM   #14
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
Originally Posted by Steven_G View Post
I'm making some progress, but not much.

I have gnome and xfce4 on the machine.

If I open the gnome-terminal and run
Code:
pidof xfce4-terminal
then I get the current pid and can kill it with
Code:
pkill -TERM -P <current pid>
But, that's only good for one shot b/c the pid changes on ever spawn. (Tested)

So how do I call pidof xfce4-terminal as a variable which I can then kill?
In your script you can put the pid of a currently running xfce4-terminal and then kill it. It should work as long as it's the only xfce4-terminal you're running at that time.


Code:
PID_TERM=$(pidof xfce4-terminal)
kill -TERM -p $PID_TERM
 
1 members found this post helpful.
Old 01-06-2016, 06:16 PM   #15
Steven_G
Member
 
Registered: Dec 2015
Location: Western US
Distribution: Home spun
Posts: 142

Original Poster
Rep: Reputation: 67
Quote:
Originally Posted by sycamorex View Post
In your script you can put the pid of a currently running xfce4-terminal and then kill it. It should work as long as it's the only xfce4-terminal you're running at that time.


Code:
PID_TERM=$(pidof xfce4-terminal)
kill -TERM -p $PID_TERM
It didn't work.

Yeah, it's the only xfce4-terminal running but that didn't work either.

And your solution is not all that different from ones I've tried by throwing spaghetti at the wall based on stuff I've found on the web.

This is starting to tick me off b/c it doesn't make any sense. (Not you guys. I appreciate the help. But things are not working the way I understand they should be based on my reading and advice from those more experienced than myself.)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting shutdown message when I try to login as anyone but root on CLI alarazr Linux - Newbie 5 07-11-2012 01:22 PM
[SOLVED] unable to execute /bin/chmod: Argument list too long veeruk101 Linux - Newbie 2 10-14-2011 06:16 AM
execute script shell with regex as argument eguider Linux - Newbie 2 12-15-2009 07:26 PM
I can execute shell script from CLI but failed to do via cron UltraSoul Linux - Software 2 06-24-2008 10:10 PM
MDV06, KDE 3.4.2 will only shutdown through CLI. Lordandmaker Linux - Newbie 1 12-05-2005 12:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration