On 12 June 2013 12:20, Ewan Slater <ewan.slater@googlemail.com> wrote:
What's wrong with kicking the script off with sudo?
This does make things a bit easier (just use something like whoami to check which user is running the script). However, it means that everything the script does now runs as root, which isn't a great idea unless that's what is required. Using sudo within the script is better, imho. I don't have any suggestions for the best way to abort if sudo fails; the ones Steve mention in the OP seem reasonable solutions at a first glance Otherwise, looking at the sudo manpage says that sudo returns the return code of the successfully run program, or 1 is unsuccessful. So sudo true .. should return 0 on success, 1 on failure, and therefore: sudo true || { echo 'Login Failed'; exit; } .. is how I would handle it, because to me just relying on echo returning 0 (true) isn't as "logical" as using true directly. -- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450 Registered in England (0456 0902) @ 13 Clarke Rd, Milton Keynes, MK1 1LG