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