how to identify if sudo is required using bash

General support questions
Post Reply
edwardsmarkf
Posts: 51
Joined: 2012/07/06 23:57:24

how to identify if sudo is required using bash

Post by edwardsmarkf » 2018/01/30 23:21:49

hello -

i have several centos-7 installations. on most of them, if i try doing "sudo su;", i get a nasty warning message. however, on those installations i can just do "su;" and log in as root. this is what happens when i use my play centos-7 on virtualbox.

however, when i try the same thing on my google-cloud centos-7 installation, i can indeed do sudo su; in addition to everything else that sudo allows me to do.

i am thinking the best way to determine the difference is something like this:

Code: Select all

if  [ '${$(groups)/sudo}' ] ;
then   SUDO='sudo' ; 
elif  [ '${$(whoami)/root' ] ;
       echo SUDO='nice';    ## 'nice' looks prettier than an empty string '' 
else
      echo 'you either need to be have sudo or be logged in as root!';
      exit;
fi;
 
##		initial installation:
${SUDO}  yum  -y  update;                 ## a good idea to start out with.
opinions?

User avatar
TrevorH
Site Admin
Posts: 33220
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: how to identify if sudo is required using bash

Post by TrevorH » 2018/01/31 01:11:11

Or just add yourself to group wheel everywhere and use sudo.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

edwardsmarkf
Posts: 51
Joined: 2012/07/06 23:57:24

Re: how to identify if sudo is required using bash

Post by edwardsmarkf » 2018/01/31 20:31:11

hello trevor - i was trying to create something a little more "generic" that could determine if sudo is required or not.

Post Reply