Hello All,
I want to create a script that will do ONLY su to any user on the server with hpadmin login using sudo. Can anyone let me know how can it do it.
Regards
Ankit
Hello All,
I want to create a script that will do ONLY su to any user on the server with hpadmin login using sudo. Can anyone let me know how can it do it.
Regards
Ankit
How about something like this (you will have to allow this script to run as root via sudo config so it can sudo su to another userid:
HPADMINUSERS=","$(grep "^hpadmin:" /etc/group | cut -d: -f4)","
if [ -n "$1" ] && [ $# -eq 1 ]
then
echo "$HPADMINUSERS" | grep -q ",$1,"
if [ $? -eq 0 ]
then
exec sudo su "$1"
else
echo "cannot su: $1 is not in group hpadmin"
fi
else
echo "usage: $0 userid" >&2
exit 1
fi