Hi Steve,
What's wrong with kicking the script off with sudo?
For example:
ewan@bluebox:~$ cat dist-upgrade.sh #!/bin/bash sudo apt-get update sudo apt-get dist-upgrade
Bad typing:
ewan@bluebox:~$ sudo ./dist-upgrade.sh [sudo] password for ewan: Sorry, try again. [sudo] password for ewan: Sorry, try again. [sudo] password for ewan: Sorry, try again. sudo: 3 incorrect password attempts ewan@bluebox:~$
Good typing: ewan@bluebox:~$ sudo ./dist-upgrade.sh [sudo] password for ewan: Hit http://extras.ubuntu.com quantal Release.gpg Hit http://ppa.launchpad.net quantal Release.gpg Hit http://security.ubuntu.com quantal-security Release.gpg Hit http://gb.archive.ubuntu.com quantal Release.gpg Hit http://extras.ubuntu.com quantal Release Hit http://ppa.launchpad.net quantal Release.gpg Hit http://gb.archive.ubuntu.com quantal-updates Release.gpg ...<yada-yada/>
Cheers,
Ewan
On 12 June 2013 12:00, main-request@lists.alug.org.uk wrote:
Send main mailing list submissions to main@lists.alug.org.uk
To subscribe or unsubscribe via the World Wide Web, visit http://lists.alug.org.uk/mailman/listinfo/main or, via email, send a message with subject or body 'help' to main-request@lists.alug.org.uk
You can reach the person managing the list at main-owner@lists.alug.org.uk
When replying, please edit your Subject line so it is more specific than "Re: Contents of main digest..."
Today's Topics:
- Exit Script if sudo password not entered (steve-ALUG@hst.me.uk)
Message: 1 Date: Tue, 11 Jun 2013 21:16:34 +0100 From: steve-ALUG@hst.me.uk To: ALUG main@lists.alug.org.uk Subject: [ALUG] Exit Script if sudo password not entered Message-ID: 51B785A2.20502@hst.me.uk Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi geniuses!
I have a few scripts with several commands prefixed by sudo. I often mistype my password, as it's complex, and, if I mistype it 3 times, I want the script to exit, rather than continue on to the next line and ask for the password again.
Is there a recommended way of doing this? I've googled & thought. One example I've seen asks for the password via zenity, then passes it through to a sudo line which does something like sudo cat /dev/nul
dev/nul and then checks if it failed - if it fails it displays a
message and quits. See: http://ubuntuforums.org/showthread.php?t=2052976&page=2
Another alternative I dreamt up whilst reading another webpage was: sudo echo || { echo 'Login Failed'; exit; }
Is there a recommended/preferred/suggested/best way of doing this?
Cheers Steve
main@lists.alug.org.uk http://www.anglian.lug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main
End of main Digest, Vol 96, Issue 15