On 12/06/13 13:11, Mark Rogers wrote:
On 12 June 2013 13:07, Mark Rogers mark@quarella.co.uk wrote:
Otherwise, looking at the sudo manpage says that sudo returns the return code of the successfully run program, or 1 is unsuccessful.
And looking more at the man sudo, sudo -v can be used to revalidate the login without running a command, so sudo -v || { echo 'Login failed'; exit; }
.. is probably the "right" way to do it.
If you want to check whether the user already has sudo rights without prompting for a password, you can do that too: sudo -nv || { echo 'Login failed'; exit; }
Fascinating what manpages will tell you about commands you use all the time :-)
Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450 Registered in England (0456 0902) @ 13 Clarke Rd, Milton Keynes, MK1 1LG
Thanks all.
Ewan, kicking off the script with Sudo is fine, provided that you remember to do it. I have a bunch of scripts, some need it, some don't. I won't reliably remember which is which.
Cheers Steve