Home » Questions » Computers [ Ask a new question ]

how to execute command after current running command in bash?

how to execute command after current running command in bash?

I'm downloading file with wget, and I want to turn off my computer after downloading will be finished, but I need to go somewhere now :) Is it possible to execute command in bash exacly when process will be finished?

Asked by: Guest | Views: 285
Total answers/comments: 2
bert [Entry]

"You can do something like this:

stop execution of wget with ctrl-z (it's not stopped, it's suspended)
put it into background (bg)
run: wait; shutdown -h now

wait will wait for all programs ran in background from current shell - i.e. this wget.

After wait will finish - shutdown will go on."
bert [Entry]

"My solutions is this: suspend your long-running task with Control+Z, then type something like:

fg; echo ""Done!""

If you want to run react differently based on the success or failure of your command, use && and || as short-circuit operators.

fg && echo ""Success!"" || echo ""Failure!""

EDIT: This won't work with sudo, because it will ask for your password. I have, accordingly, removed the examples using sudo. If you need sudo for the second task, use another of the methods posted here.

On the other hand, I believe that both GNOME and KDE offer ways to trigger a shutdown/reboot without using sudo, by sending an appropriate D-Bus signal or something."