LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shutdown PC after command is done? (https://www.linuxquestions.org/questions/linux-newbie-8/shutdown-pc-after-command-is-done-4175676063/)

crts 05-31-2020 05:49 PM

Quote:

Originally Posted by Hermani (Post 6129402)
Maybe I am just a fan of simple solutions. But I am still a n--b as well..

What is wrong with something like

Code:

> command_to_run && shutdown now

Mainly two issues here. First, as has already been previously stated, the shutdown must be issued as root, while the command_to_run is issued as normal user. Your solution does not address that.

Second, as I understand it, OP wants to shutdown after the job finishes. Your solution will only execute shutdown if the job finishes successfully, i.e., if the first command fails for some reason then the machine will not shutdown.

Hermani 06-01-2020 04:12 PM

Quote:

Originally Posted by crts (Post 6129431)
Second, as I understand it, OP wants to shutdown after the job finishes. Your solution will only execute shutdown if the job finishes successfully, i.e., if the first command fails for some reason then the machine will not shutdown.

Thanks. You're right; however I did not know that if the first command does not exit succesfully. the second does not run.

wpeckham 06-01-2020 07:59 PM

Quote:

Originally Posted by Hermani (Post 6129728)
Thanks. You're right; however I did not know that if the first command does not exit succesfully. the second does not run.

Seek documentation of the meaning and behavior of && for details. Your solution is not wrong, but it may not have the behavior that the OP desires (or described).


All times are GMT -5. The time now is 03:41 AM.