Original Message:
Sent: Thu July 20, 2023 11:27 PM
From: Dao Tien Dat
Subject: Displays password change warning for root user
Hi, I'm trying to use your script but has an error about syntax: 0403-057 Syntax error at line 5 : `then' is not expected.
Can you help me about it. Thank you
------------------------------
Dao Tien Dat
------------------------------
Original Message:
Sent: Wed July 12, 2023 07:38 AM
From: Marcin Marciszewicz
Subject: Displays password change warning for root user
Hello,
In general, I created the script thanks to your help :)
I have implemented the command passwd and passwd $USER, then check whether the user belongs to the correct group and whether the logged in user is root.
#!/bin/ksh
USER="`/usr/bin/whoami | awk '{print $1}'`"
SGROUP="`id -gn ${USER}`"
if [[ ${1} == "" ]];then
if [[ $SGROUP=="system" ]] && [[ $USER=="root" ]];then
echo "#####################################################################
# #
# This operation can cause serious problems. #
# Changing the root password may result in a problem with the #
# operation of the client application #
# #
#####################################################################
Press Enter to continue changing `whoami` password"
read hold
/usr/bin/passwd
fi
elif [[ ${1} == "root" ]];then
if [[ $SGROUP=="system" ]] && [[ $USER=="root" ]];then
echo "#####################################################################
# #
# This operation can cause serious problems. #
# Changing the root password may result in a problem with the #
# operation of the client application #
# #
#####################################################################
TEST Press Enter to continue changing `whoami` password"
read hold
/usr/bin/passwd ${1}
fi
fi
I added to the .profile of the root user the path to the script
I assigned run permissions and everything works as I expected.
Is there any way to optimize it better?
Thank you all for the tips.
------------------------------
Marcin Marciszewicz
Original Message:
Sent: Wed June 28, 2023 09:04 AM
From: Henrik Morsing
Subject: Displays password change warning for root user
Hi Marcin,
You could define a function that calls the actual password command.
Regards,
Henrik Morsing
------------------------------
Henrik Morsing
Original Message:
Sent: Thu June 22, 2023 11:14 AM
From: Marcin Marciszewicz
Subject: Displays password change warning for root user
Hi,
I will try to check this solution next week
Thanks a lot
------------------------------
Marcin Marciszewicz
Original Message:
Sent: Thu June 22, 2023 09:03 AM
From: Fazel Vayalilagathu
Subject: Displays password change warning for root user
You can add a wrapper script as below and name it passwd and keep it in a directory that is in first search order in PATH variable.
====================================================================
if [ ${1} == "root" ];then
echo "This operation can cause major issues..."
echo "Press Enter to continue changing ${1} password"
read hold
passwd ${1}
else
passwd ${1}
fi
=============================================================================
This will give you the expected results I believe.
------------------------------
Fazel Vayalilagathu