Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
shutting your pc down when emerge is finished
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
dippen
Tux's lil' helper
Tux's lil' helper


Joined: 15 Sep 2002
Posts: 83

PostPosted: Sat Dec 21, 2002 3:04 am    Post subject: shutting your pc down when emerge is finished Reply with quote

you know that, you sitting in front of your pc, its late at night.
you wanna go sleeping, but you think : emerge -u world will finish in few minutes.. and you wait and wait..
i got a solution.. very trivial, but it works:
start this script and your computer halts if the emerge-process is finished.
i call it haltAfterEmerge.sh
Code:
#!/bin/bash

while [ 1 ]; do

        if [ -z "`ps -e | grep python`" ]; then
                /sbin/halt;
                exit;
        fi;

        sleep 2;
done;

it looks every two seconds for a python-process (emerge is one),
if it can't find one, it executes '/sbin/halt'

you can substitute '/sbin/halt' with 'printf \\a', then it beeps every
two seconds.... maybe to wake you up ;) -- in some situations useful.

greetz,
dippen

excuse my poor english.. i'm working on it.
Back to top
View user's profile Send private message
pizen
Apprentice
Apprentice


Joined: 23 Jun 2002
Posts: 213
Location: Atlanta, GA, USA

PostPosted: Sat Dec 21, 2002 6:40 am    Post subject: Reply with quote

why not just:
Code:
$ emerge <whatever> && /sbin/halt
Back to top
View user's profile Send private message
bos_mindwarp
Apprentice
Apprentice


Joined: 19 Oct 2002
Posts: 275
Location: stockholm, sweden

PostPosted: Sat Dec 21, 2002 8:36 am    Post subject: Reply with quote

pizen wrote:
why not just:
Code:
$ emerge <whatever> && /sbin/halt


because it's not high-tech? =)
Back to top
View user's profile Send private message
snutte
Apprentice
Apprentice


Joined: 24 Apr 2002
Posts: 181
Location: Sweden, Malmö

PostPosted: Sat Dec 21, 2002 8:54 am    Post subject: Reply with quote

My vote is for the
Code:

emerge <whatever> && poweoff
Back to top
View user's profile Send private message
kram
n00b
n00b


Joined: 29 Nov 2002
Posts: 35

PostPosted: Sat Dec 21, 2002 9:37 am    Post subject: Reply with quote

pizen wrote:
why not just:
Code:
$ emerge <whatever> && /sbin/halt

I do
Code:
$ emerge <whatever> &> ~/build.log; /sbin/halt

so it shuts down regardless of whether the build was successful.

Can you do this once you've already started a build? Maybe if openoffice has been building for 3 hours already? :)
Back to top
View user's profile Send private message
dippen
Tux's lil' helper
Tux's lil' helper


Joined: 15 Sep 2002
Posts: 83

PostPosted: Sat Dec 21, 2002 3:37 pm    Post subject: Reply with quote

Quote:
$ emerge <whatever> && /sbin/halt

is the easiest way..

if i start an 'emerge <whatever>', i mostly dont know
if i want to shut down my computer when it is finished..
so if i want it, then i start my script.


and yes, i'm glad that its a VERY high-tech solution ;)
Back to top
View user's profile Send private message
carambola5
Apprentice
Apprentice


Joined: 10 Jul 2002
Posts: 214

PostPosted: Sat Dec 21, 2002 6:37 pm    Post subject: Reply with quote

pizen wrote:
why not just:
Code:
$ emerge <whatever> && /sbin/halt


I think you're missing the point. The script is an "afterthought" type of thing. Say you start a merge, but after awhile, you realize it's gonna take longer than expected. If you want to do something after it's done (shutdown or beep at you), you have two choices:
  • Stop the merge, and restart it with the command "emerge <blah> && /sbin/halt"
  • Or, start a script with the functionality of the original post's.

I'm guessing that, since this is usually done with longer merges, that you wouldn't want to restart the process.

One interesting aspect of the function behind this script is a theoretical GUI frontend to emerge. If the user starts a batch of emerges, he/she can apply a notification event even after the emerges start by simply toggling a button.
Back to top
View user's profile Send private message
carambola5
Apprentice
Apprentice


Joined: 10 Jul 2002
Posts: 214

PostPosted: Sat Dec 21, 2002 6:37 pm    Post subject: Reply with quote

grr. double post.
Back to top
View user's profile Send private message
pizen
Apprentice
Apprentice


Joined: 23 Jun 2002
Posts: 213
Location: Atlanta, GA, USA

PostPosted: Sat Dec 21, 2002 6:55 pm    Post subject: Reply with quote

carambola5 wrote:
I think you're missing the point. The script is an "afterthought" type of thing.
I realized this after reading a few posts after mine.
Back to top
View user's profile Send private message
snutte
Apprentice
Apprentice


Joined: 24 Apr 2002
Posts: 181
Location: Sweden, Malmö

PostPosted: Sat Dec 21, 2002 9:59 pm    Post subject: Reply with quote

Btw, shutting down your computer? Hmm.. never thought of that :wink:
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sat Dec 21, 2002 11:28 pm    Post subject: Reply with quote

kram wrote:
Can you do this once you've already started a build?
Try:
Code:
# emerge openoffice
... emerge doing its thing ...
^Z
# fg; poweroff

_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
carambola5
Apprentice
Apprentice


Joined: 10 Jul 2002
Posts: 214

PostPosted: Mon Dec 23, 2002 3:06 am    Post subject: Reply with quote

delta407 wrote:
kram wrote:
Can you do this once you've already started a build?
Try:
Code:
# emerge openoffice
... emerge doing its thing ...
^Z
# fg; poweroff


Sweet! Thanks. I've always wondered why one would suspend a job rather than kill it. I never knew how to restart a job if it had been suspended.
Back to top
View user's profile Send private message
water
Guru
Guru


Joined: 19 Jun 2002
Posts: 387
Location: Zierikzee, The Netherlands

PostPosted: Mon Dec 23, 2002 9:50 am    Post subject: Reply with quote

And i stil don't know. :?

What does "fg"? And how do i restart after a reboot? Just emerge blahblah again (if blahblah was the emerge i stopped)?
_________________
Groeten uit Holland
Back to top
View user's profile Send private message
Lolo-
n00b
n00b


Joined: 04 Aug 2002
Posts: 62
Location: SQY (France)

PostPosted: Mon Dec 23, 2002 4:42 pm    Post subject: Reply with quote

fg -> foreground
bg -> background, you can launch another process right now
Back to top
View user's profile Send private message
Spiregrain
n00b
n00b


Joined: 17 Mar 2003
Posts: 5
Location: London

PostPosted: Sun Sep 07, 2003 8:41 pm    Post subject: Even easier aftertought method... Reply with quote

When emerge is building, I often want to suspend the machine as soon as it's finished... so I just type apm -s<return> into the emerge window. As soon as the build is finished the characters you've typed in will appear on the command line, and get executed.
Back to top
View user's profile Send private message
Ian
l33t
l33t


Joined: 28 Oct 2002
Posts: 834
Location: Somerville, MA

PostPosted: Sun Sep 07, 2003 10:43 pm    Post subject: Reply with quote

Wow, I never knew about that ^Z command before. That's so cool!!

Yes, I do feel like a little kid who just got another matchbox car :p.
Back to top
View user's profile Send private message
Ox-
Guru
Guru


Joined: 19 Jun 2003
Posts: 305

PostPosted: Sun Sep 07, 2003 11:13 pm    Post subject: Reply with quote

For those who didn't know about ^Z or fg, this is documented in the job control section of the man page for your shell.
Code:
man bash
/JOB CONTROL
or:
Code:
man tcsh
/Jobs

There are a lot of goodies like this in the shells :)
Back to top
View user's profile Send private message
RobMcM
Apprentice
Apprentice


Joined: 11 Jul 2003
Posts: 170
Location: Leeds, UK

PostPosted: Sun Oct 05, 2003 2:22 pm    Post subject: Reply with quote

carambola5 wrote:
delta407 wrote:
kram wrote:
Can you do this once you've already started a build?
Try:
Code:
# emerge openoffice
... emerge doing its thing ...
^Z
# fg; poweroff


Sweet! Thanks. I've always wondered why one would suspend a job rather than kill it. I never knew how to restart a job if it had been suspended.



Just make sure you don't do the stupid thing I did, when towards the end of a KDE emerge I did 'bg; poweroff' instead of 'fg; poweroff' ! Oops, instant shutdown 8O
_________________
Keyboard error or no keyboard present. Press F1 to continue.
Back to top
View user's profile Send private message
bazik
Retired Dev
Retired Dev


Joined: 22 Jul 2002
Posts: 277
Location: Behind you.

PostPosted: Sun Oct 05, 2003 10:38 pm    Post subject: Reply with quote

Funny, I submitted a patch for portage which adds PRE- and POST- emerge commands a while ago.
Back to top
View user's profile Send private message
st589
Tux's lil' helper
Tux's lil' helper


Joined: 20 Sep 2003
Posts: 83

PostPosted: Sun Oct 05, 2003 10:46 pm    Post subject: Reply with quote

water wrote:
And i stil don't know. :?

What does "fg"? And how do i restart after a reboot? Just emerge blahblah again (if blahblah was the emerge i stopped)?

I'm wondering this also :o Anyone know?
Back to top
View user's profile Send private message
RobMcM
Apprentice
Apprentice


Joined: 11 Jul 2003
Posts: 170
Location: Leeds, UK

PostPosted: Sun Oct 05, 2003 11:20 pm    Post subject: Reply with quote

st12af wrote:
water wrote:
And i stil don't know. :?

What does "fg"? And how do i restart after a reboot? Just emerge blahblah again (if blahblah was the emerge i stopped)?

I'm wondering this also :o Anyone know?


look a couple of posts up for the bash man pages...

When there is a suspended process (like when you've used ^Z on an emerge) then
Code:
# fg
will bring the suspended process back into the foreground which is how it was before you used ^Z.
Code:
# bg
runs it in the background instead meaning it continues to run but you can still type stuff into the shell, like you can when you run something with the ampersand after it:
Code:
# prog&
--- prog running in background ---
# other stuff here

_________________
Keyboard error or no keyboard present. Press F1 to continue.
Back to top
View user's profile Send private message
Squinky86
Retired Dev
Retired Dev


Joined: 25 Mar 2003
Posts: 309
Location: Alabama, USA

PostPosted: Mon Oct 06, 2003 1:19 am    Post subject: Reply with quote

While on this note, another neat thing related to fg and bg but if you're ssh'd and want to close the client computer:
# nohup emerge -uf world &
// <check nohup.txt to make sure package1 is downloaded>
# nohup emerge -u world && halt &
# exit

That's the quickest way to have emerge run on an ssh'd box you want shutdown after the upgrade. If not using ssh, it's good to replace "nohup * &" with "bg" for the emerge -uf world, and have emerge -u world run in sight to make sure nothing goes wrong.

Just my ways of speeding up portage ;).
_________________
Me
Back to top
View user's profile Send private message
Ian Goldby
Guru
Guru


Joined: 18 May 2002
Posts: 539
Location: (Inactive member)

PostPosted: Mon Oct 06, 2003 7:05 pm    Post subject: Reply with quote

Another handy emerge script:
Code:
#!/bin/bash
#
# Display system load on the keyboard LEDs
# This must be run from a console (not inside X)

while [ 1 ]
do
  loadavg=`cut -d" " -f1 /proc/loadavg`
  if [[ $loadavg < 0.25 ]] ; then
    setleds -L -num -caps -scroll
  else
    if [[ $loadavg < 0.5 ]] ; then
      setleds -L +num -caps -scroll
    else
      if [[ $loadavg < 0.75 ]] ; then
        setleds -L +num +caps -scroll
      else
        setleds -L +num +caps +scroll
      fi
    fi
  fi
  sleep 5
done

Switch to a console window (e.g. ctrl-alt F1) and run this. Then turn off the monitor and go and do something else. The keyboard LEDs act as a CPU load meter. Poke your head round the door an hour later and if the LEDs are out, emerge has probably finished.
Back to top
View user's profile Send private message
dub.wav
Tux's lil' helper
Tux's lil' helper


Joined: 09 Apr 2003
Posts: 149
Location: Norway

PostPosted: Mon Oct 06, 2003 7:21 pm    Post subject: Reply with quote

Ian Goldby wrote:
Another handy emerge script:
Code:
#!/bin/bash
#
# Display system load on the keyboard LEDs
# This must be run from a console (not inside X)

while [ 1 ]
do
  loadavg=`cut -d" " -f1 /proc/loadavg`
  if [[ $loadavg < 0.25 ]] ; then
    setleds -L -num -caps -scroll
  else
    if [[ $loadavg < 0.5 ]] ; then
      setleds -L +num -caps -scroll
    else
      if [[ $loadavg < 0.75 ]] ; then
        setleds -L +num +caps -scroll
      else
        setleds -L +num +caps +scroll
      fi
    fi
  fi
  sleep 5
done

Switch to a console window (e.g. ctrl-alt F1) and run this. Then turn off the monitor and go and do something else. The keyboard LEDs act as a CPU load meter. Poke your head round the door an hour later and if the LEDs are out, emerge has probably finished.

Cool :) Do you know if there's a xfree equivalent of setleds? After a etc-update a few weeks ago, I have to press num lock each time I restart X to be able to type / in rxvt.
Back to top
View user's profile Send private message
PanTast
n00b
n00b


Joined: 29 Sep 2003
Posts: 5
Location: Germany

PostPosted: Mon Oct 06, 2003 10:20 pm    Post subject: Reply with quote

my way:
I worte a "emma.bat" like this

emerge -k xine
emerge -k mplayer
emerge -k whateveryouwant
halt


make a chmod u+x and run it as root

The advantage is: when you forgot something, you can add it to the emma.bat before the halt order.

8)
_________________
2 young 2 die but never 2 old 2 rock ´n roll
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum