You are not logged in.

#1 2010-03-13 10:35:11

tawan
Member
Registered: 2010-03-02
Posts: 290
Website

Append command to running command [solved]

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

#2 2010-03-13 11:12:53

Sadface
Member
From: Germany
Registered: 2009-12-09
Posts: 47

Re: Append command to running command [solved]

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

#3 2010-03-13 11:46:28

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: Append command to running command [solved]

^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

#4 2010-03-13 12:02:09

tawan
Member
Registered: 2010-03-02
Posts: 290
Website

Re: Append command to running command [solved]

JohannesSM64 wrote:

^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.

Interesting, I'll try that thanks.

Offline

#5 2010-03-13 15:47:11

cmtptr
Member
Registered: 2008-09-01
Posts: 135

Re: Append command to running command [solved]

wait $(pgrep rsync) && sudo shutdown -h now

Offline

#6 2010-03-14 00:01:33

tawan
Member
Registered: 2010-03-02
Posts: 290
Website

Re: Append command to running command [solved]

^ really? That looks smart

I have to read up on that

Offline

#7 2010-03-14 02:41:32

cmtptr
Member
Registered: 2008-09-01
Posts: 135

Re: Append command to running command [solved]

tawan wrote:

^ 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

#8 2010-03-14 02:56:10

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Append command to running command [solved]

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

#9 2010-03-14 07:19:58

chpln
Member
From: Australia
Registered: 2009-09-17
Posts: 361

Re: Append command to running command [solved]

Gen2ly wrote:

hmm, do you want to halt though.  If I remember correctly 'halt' will do exactly that.

halt(8) wrote:

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

Board footer

Powered by FluxBB