LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-21-2006, 06:23 PM   #1
tuxedo-notebook
Member
 
Registered: Oct 2003
Distribution: Gentoo 2.6.12, Mepis 2.6.7, KUbuntu PPC
Posts: 43

Rep: Reputation: 15
Doing a "friendly" shutdown


I'm running Arch Linux with Openbox and I have a few programs that start automatically on boot for me (like XMMS, it's a DJ comp.) I'd like to write a script or something that will shutdown the computer so that these apps won't need to be manually closed. I want to close the programs the friendly way (equivlant of pushing the x or doing Alt-F4) rather than just doing halt and killing all of them because I want them to save their configuration on exit. How can I do this?
 
Old 03-21-2006, 06:35 PM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Your script should kill(1) each process then issue a shutdown(8) command. Or, is this not what you're after?

Have you noticed that when you hover your mouse over a title, the first line of that post pops up? Thus, it is useful for folk looking through the zero-reply threads if the first line contains some detail. The "Hi;" can come next
 
Old 03-21-2006, 10:12 PM   #3
tuxedo-notebook
Member
 
Registered: Oct 2003
Distribution: Gentoo 2.6.12, Mepis 2.6.7, KUbuntu PPC
Posts: 43

Original Poster
Rep: Reputation: 15
Kill and shutdown are all fine and well, but I'm looking more to tell the apps to please close rather than killing them without question. I want the app's exit code to run.

I hadn't noticed that. Thanks for the tip!
 
Old 03-22-2006, 01:47 AM   #4
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
kill <pid> will run the programs exit code. With no arguments, kill is just basically saying to the program "well, it's time to go champ" and the head goes down, he chucks the gloves and walks off (sorry, been watching the boxing on TV ). Now something like kill -9 <pid> is cutting it's head off which you don't want to do. kill <pid> or killall <app_name> is what you're after
 
Old 03-22-2006, 01:57 AM   #5
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,645

Rep: Reputation: 146Reputation: 146
I started to write a script for that myself when using Openbox. Since I now use IceWM which does that for me (close all apps and let them save configuration files) I do not longer need one.
My idea was to send the kill signal and catch those apps that need further action like saving a file and ask the user for the name to save the file as. I used wmctrl for this (google for it) but I gess you could use the kill command purely for the kill part of this.
Notice that there was some kind of bug in the script I didn't solve (and I don't remember it to be honest) -- because it did what I mainly wanted: It sends the X apps an kill command but allows them to give the user "save" dialog as well as an button to allow the shutdown with one click. I hope it helps with your task

Code:
# send all apps (except aterm and pypanel) the HUP signal
for app in `wmctrl -l | grep -v panel | grep -v aterm`; do  
   wmctrl -c "$app"
done

sleep 3

# bring possible save requests to foreground
wmctrl -a "Save Message"         # Thunderbird
wmctrl -a "Microsoft Word"       # Word
wmctrl -a "OpenOffice.org 2.0"   # OpenOffice
wmctrl -a "Confirm close"        # Firefox > 1 tabs
wmctrl -a "Dokumente speichern"  # kate
wmctrl -a "Dokument schlie"      # kwrite
wmctrl -a "LyX"                  # LyX LaTeX editor
wmctrl -a "Save File"            # nedit 

Xdialog --title "Shutdown" --default-no --yesno "Shut down?\n \
Data will not be automatically saved! " 10 50 
# catch Xdialog's exit code
EXIT_CODE=$?

# process Xdialog's exit code
case $EXIT_CODE in
    0) # Continue
       sudo /sbin/shutdown -h now
       ;;
    1) # Cancel/No pressed.
       exit 0
       ;;
  255) # An error occured or the box was closed.
       exit 1
       ;;
esac

exit 0
 
Old 03-22-2006, 05:13 PM   #6
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Quote:
Originally Posted by tuxedo-notebook
Kill and shutdown are all fine and well, but I'm looking more to tell the apps to please close rather than killing them without question. I want the app's exit code to run.
There have been many suggestions since I last looks - well done guys I'd like to point out that many systems actually do what you want for you if you give them a chance ... like if you put a time-delay on the shutdown command. Is there any particular app you are having trouble with?
Quote:
I hadn't noticed that. Thanks for the tip!
A neat excersize is to do a mouse hover over search results (like 0 reply threads) and see who knows about this and who dosn't ...also provides a good tutorial on how to write questions. I think it's a cool feature - makes up for all those "I have a question" titles.

Another useful tip is to quote a bit of what you are replying to - even if you think it's obvious (I was stumped for a few seconds before I realised what you were responding to in which bit). If this is just a quicky reply - you can still copy-and-paste the line you want and box it with the bv code. That's how the experienced folk get all those coll effects.

Have fun.
 
Old 03-22-2006, 06:09 PM   #7
crAckZ
Member
 
Registered: Sep 2004
Location: LOUISVILLE KENTUCKY
Distribution: mandriva 2006
Posts: 155

Rep: Reputation: 30
Quote:
Originally Posted by Simon Bridge

Have you noticed that when you hover your mouse over a title, the first line of that post pops up? Thus, it is useful for folk looking through the zero-reply threads if the first line contains some detail. The "Hi;" can come next
not to get off topic or hijack but if te first line is "hi" i just go to the next one, and even faster if the title is'nt descriptive.
 
Old 03-22-2006, 06:35 PM   #8
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Quote:
not to get off topic or hijack but if te first line is "hi" i just go to the next one, and even faster if the title is'nt descriptive.
"next one" what? the next line or the next thread?

Failing to be informative in the title (and now there is a second chance with the mouse-over preview) runs the risk that someone who wants to help will dismiss the thread and move on to the next one. (Unfortunately, the poster will never learn by this method.)

If, however, you mean that you go to the next line (more strongly implied by the context), I'd like to know how to do this without clicking on the title first. (This feature is in the search results pane remember.)

Last edited by Simon Bridge; 03-22-2006 at 06:40 PM.
 
Old 03-22-2006, 11:27 PM   #9
tuxedo-notebook
Member
 
Registered: Oct 2003
Distribution: Gentoo 2.6.12, Mepis 2.6.7, KUbuntu PPC
Posts: 43

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by cs-cam
kill <pid> will run the programs exit code. With no arguments, kill is just basically saying to the program "well, it's time to go champ" and the head goes down, he chucks the gloves and walks off (sorry, been watching the boxing on TV ). Now something like kill -9 <pid> is cutting it's head off which you don't want to do. kill <pid> or killall <app_name> is what you're after
Didn't work that way for me. Still off with the head.

Quote:
Originally Posted by Simon Bridge
I'd like to point out that many systems actually do what you want for you if you give them a chance ... like if you put a time-delay on the shutdown command.
Immediate kill even with a delayed shutdown on my system.

Quote:
Originally Posted by titopoquito
I started to write a script for that myself when using Openbox. Since I now use IceWM which does that for me (close all apps and let them save configuration files) I do not longer need one.
My idea was to send the kill signal and catch those apps that need further action like saving a file and ask the user for the name to save the file as. I used wmctrl for this (google for it) but I gess you could use the kill command purely for the kill part of this.
Notice that there was some kind of bug in the script I didn't solve (and I don't remember it to be honest) -- because it did what I mainly wanted: It sends the X apps an kill command but allows them to give the user "save" dialog as well as an button to allow the shutdown with one click. I hope it helps with your task
Exactly what I needed. Thanks a lot titopoquito! I used your dialog code with wmctrl -c "dialog name" to close all the apps with sleep to wait a little bit before doing sudo halt.

Quote:
Originally Posted by Simon Bridge
If, however, you mean that you go to the next line (more strongly implied by the context), I'd like to know how to do this without clicking on the title first.
The newlines in a post are displayed as symbols in the alt text so if someone starts out with hi and hits return a couple times you still see the beginning of their actual post. So you can read the next line without clicking on the title first.
 
Old 03-23-2006, 02:44 AM   #10
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Quote:
Originally Posted by tuxedo-notebook
The newlines in a post are displayed as symbols in the alt text so if someone starts out with hi and hits return a couple times you still see the beginning of their actual post. So you can read the next line without clicking on the title first.
Yeah, naturally... hello CR CR I need help with blah blah (all one line) ... however, don't I need to be looking at the source to see the alt text? (Me use firefox BTW.)
 
Old 03-23-2006, 03:24 AM   #11
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,645

Rep: Reputation: 146Reputation: 146
Quote:
Originally Posted by tuxedo-notebook
Exactly what I needed. Thanks a lot titopoquito! I used your dialog code with wmctrl -c "dialog name" to close all the apps with sleep to wait a little bit before doing sudo halt.
Glad I could help
 
Old 03-23-2006, 08:15 PM   #12
tuxedo-notebook
Member
 
Registered: Oct 2003
Distribution: Gentoo 2.6.12, Mepis 2.6.7, KUbuntu PPC
Posts: 43

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Simon Bridge
Yeah, naturally... hello CR CR I need help with blah blah (all one line) ... however, don't I need to be looking at the source to see the alt text? (Me use firefox BTW.)
As I understand it the alt text is what you see when you mouseover the posts. Clever of them to php the first chars into the alt tex--I like the uber compatibility of that method. Naturally, I use Firefox too.

Oh, and thanks to everyone who responded. I forgot to mention that in the last post.
 
Old 03-25-2006, 04:19 AM   #13
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
So more puzzle - with mousover, I get to see only the first line of the alt text in a thin yellow box. I've been trying to guess how to get the other lines - the carriage returns are not displayed as a character for me, but as new lines. Same if I view the alt-text in the source.

So, I guess the question gets rephrased: how did you get firefox to show CR's in alt-text as characters? (And thus be able to view the entire preview and not just the first line.)
 
Old 03-25-2006, 05:47 PM   #14
tuxedo-notebook
Member
 
Registered: Oct 2003
Distribution: Gentoo 2.6.12, Mepis 2.6.7, KUbuntu PPC
Posts: 43

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Simon Bridge
So more puzzle - with mousover, I get to see only the first line of the alt text in a thin yellow box. I've been trying to guess how to get the other lines - the carriage returns are not displayed as a character for me, but as new lines. Same if I view the alt-text in the source.

So, I guess the question gets rephrased: how did you get firefox to show CR's in alt-text as characters? (And thus be able to view the entire preview and not just the first line.)
Interesting. I get symbols on both of the comps sitting infront of me running Firefox in MEPIS and Gentoo Linux. However, the symbols are different between computers which leads me to believe it has something to do with the charachter set. I didn't change any settings in Firefox to do with that anyway. I get new lines in the source too.
 
Old 03-26-2006, 09:43 PM   #15
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Hmmm... looks like it may be a Fedora/Ubuntu thing - or maybe it is the firefox version?

The firefow I got in front of me now is the fedora distro version: 1.0.7-1.1.fc4 (i386) ... Ubuntu also has 1.0.7 ... these are both regularily updated from the distro repositories. The latest version in the fedora yum repo is: 1.0.7-1.2.fc4 for eg.

I wonder if it would be worth updating to fx 1.5 ... but surely these patch versions work out very close? (If this goes much further, I'll take it to another thread so everyone can play.)
 
  


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
"shutdown" and "halt" symlinks: poweroff, reboot. sud_crow Linux From Scratch 11 10-17-2006 11:03 PM
Computer is not turning off after "init 0" or "shutdown -h now" f430 Linux - General 5 12-17-2005 02:54 AM
Can't "shutdown -a -r now" as a normal user, though shutdown.allow exists mnemonic Linux - Software 5 08-15-2005 06:49 PM
What's the difference between "shutdown -h now" and "halt"? shadkong Slackware 2 04-07-2005 12:43 AM
Removing "shutdown" and "reboot" in logout window nearfar Red Hat 1 10-07-2003 11:33 AM

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

All times are GMT -5. The time now is 06:16 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