[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shutdown computer after a specific command has been executed



On 09/12/13 11:42, Muntasim-Ul-Haque wrote:
> Hi,
> I need a tool that would make sure that, my computer would shutdown
> after a specific command has been executed. This tool would just wait
> for the Terminal for executing a command, like '/sudo apt-get upgrade/'
> and then after the command has been executed, my computer would
> shutdown. Is that possible? Is there a tool or anything out there that
> can do this for me? Let me know. It would be of great help. Thanks in
> advance.
> Muntasim-Ul-Haque
to shut down the computer from a script or command line use
   shutdown -h now
It needs elevated(root) permissions so initially I was tempted to use
   sudo shutdown -h now

but I think sudo has a timeout after which it prompts you to re-enter
your password, probably not what you want.

So the solution would be to "sudo" everything and drop to a regular user
to run your command, unless it too needs to be run as root.

My bash scripting isn't sharp enough to do it but here's a place to
start from for user "bob", uid=1001

   sudo { su -l bob -c 'echo "$UID"' }; echo "$UID"

Yes it doesn't work, but if you can tweak it to output "1001" and "0"
then you've solved it.

Maybe it's easier to create a script file that takes your command then
shuts down.

There are also other ways to do this that depend on which desktop
environment you're using.


Reply to: