Originally posted by cscott
Huh? I don't understand. In your first post you suggested this code, now you are saying that it doesn't work and will destroy the CD.
Anyhow, I'm still looking for a way to automatically turn off my pc after all unattended programs are finished. Maybe I need to look at bash's job control for a solution.
No!!! In my post i suggested this : cdrecord -v -eject speed=2 dev=0,1,0 -dao file.iso ; /sbin/halt
Without & in the end of cdrecord command. When you put & in bash this means run the command in the background.
When put & the process becomes a daemon. It is not attached to the console any more (well, not exactly) and the prompt is returned to the console and you may execute another command in the console, without having terminated the previous command. So /sbin/halt, will be executed write after cdrecord is executed, without leting cdrecord finish.
Actually when you put & you shouldn't put ; because it's wrong, so the second command I posted wouldn't work anyway. I'll correct it in the post.
To see the difference try this:
xmms; echo "echo has just been executed"
xmms & echo "echo has just been executed"
In the first command the echo part will be executed after you close xmms.
In the second command the echo part will be executed right after xmms starts.
The problem is that some programs are daemons be default and in those programs the
<program>; <program> scheme won't work.
Also check theYinYeti's watch.sh script. It may do the job for you.
Build a simple script to test it like my test_watch script.
skalkoto@darkstar:~$ cat test_watch
while [ 1 ]; do
And execute it. This contain a dummy loop that will never stop until u kill it(CTRL +C). Open a condole and execute the script.
Then open another console and execute theYinYeti's watch.sh after you make sure you replace bell.sh with echo "$1 program has finished" like this:
skalkoto@darkstar:~$ cat watch.sh
# This script scans the output of "ps -e" every $1 seconds, until grep
# does not find $2 in this output anymore, then bell.sh is called.
# Copyright (C) 2004,2005 Yves Gablin (firstname.lastname@example.org)
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation: http://www.gnu.org/licenses/gpl.html
# $1 : "sleep" parameter (see "sleep" man page)
# $2 : "grep" parameters (this is a regular expression)
# Usage examples:
# watch.sh 1m make # scan every minute
# watch.sh 15 make # scan every 15 seconds
while [ -n "$(ps -e -o cmd | grep "$@" | grep -vF "$this" | grep -vF grep)" ]; do
echo "$1 program has finished"
skalkoto@darkstar:~$ ./watch.sh 1 test_watch
The echo will be executed after test_watch has finished/killed
If you replace the echo with /sbin/halt this will be executed after the program you are watching has finished