You are not logged in.
Imagine I have just run an update or a backup or some long process with an approximate finish time ~ it will take about 30 minutes to complete.
My wife (she's the boss) has just decided we need to go out to some 'important' event.
I want my computer to shutdown after the update is complete.
Best I can do is open a terminal and say '# shutdown +35' and hope that the update/backup completes before the shutdown is called.
Obviously this may cause a problem if the update/backup is not complete.
~
The question is how to append one command to the end of the running command. So I can issue shutdown and it will work after the running command is done and not some guessed time in the future.
Last edited by tawan (2010-03-13 12:02:30)
Offline
I don't think there's a thing like "appending" a command.
But I do think you could just write a script that constantly checks for the running process, and once it ends call the shutdown command.
Offline
^Z to suspend then
fg; sudo halt
edit: i'll expand on that.. focus the terminal where the update is running, press Ctrl+z, then type
fg; sudo halt
and press enter.
Last edited by JohannesSM64 (2010-03-13 11:58:02)
Offline
Offline
wait $(pgrep rsync) && sudo shutdown -h now
Offline
^ really? That looks smart
I have to read up on that
Maybe not as smart as I thought. On second try, it seems you can use wait only on processes that are children of the shell from which "wait" was invoked. So unless your backup program was already running in the background you might as well use JohannesSM64's solution.
Offline
These are cool, never really thought of that, particularly yours Johannes. Putting a command after foreground... hmm, do you want to halt though. If I remember correctly 'halt' will do exactly that. I believe that is the command the init scripts use after everything else is quit/force stopped before reboot/shutdown. Or am I wrong on that?
The wait I hadn't thought of either (never really used it). So wait just polls (every second or so) and when the pid is gone... shamu?... huh.
Last edited by Gen2ly (2010-03-14 02:57:05)
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
hmm, do you want to halt though. If I remember correctly 'halt' will do exactly that.
If halt or reboot is called when the system is not in runlevel 0 or 6, in other words when it's running normally, shutdown will be invoked instead (with the -h or -r flag).
Both usages are perfectly valid.
Offline