2

I am using Ubuntu 14.04 and looking for updating an script to allow passwordless powering off my machine after executing set of commands.

To do so, I have configured sudo shutdown now and it does the jop. However, my question is

How to update that command so that it prompts me an option choice ( y / n ) with timeout ? ...to choose whether to shutdown now or not. If no answer is provided after the time is out then shutdown.

2
  • I do not think now accepts any more parameters. Instead you can think about adding +m (i.e minutes) after which the system will shutdown (and you can cancel with ctrl+c)
    – Ron
    Jun 26, 2015 at 5:54
  • related (for Unity): askubuntu.com/questions/554576/…
    – Takkat
    Jun 26, 2015 at 6:36

1 Answer 1

0

After a quick web search, and a little inventiveness, here's what I came up with.

#! /bin/bash
read -p "Do you want to shutdown (Y/N)" yn
case $yn in
     [Yy]* ) sleep 30 && sudo shutdown now;;
     [Nn]* ) exit;;
     * ) echo "Please answer Y or N.";;
esac

When I ran it, it quit back to command prompt when I selected N, and went to shutdown when I selected Y. However, it seemed to reboot, and when I put in my passwd in the login prompt, THEN it shut down. YMMV. Feel free to expand, test, or change it to your hearts content.

Sorry, didn't read about the time out. Edited post to include it. If you want timeout to be related to how long you have the choice, I'll have to look into it more, but it currently will wait 30 seconds, then shutdown if you select Y.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .