1745782 Members
3608 Online
108722 Solutions
New Discussion юеВ

Scripting

 
SOLVED
Go to solution
Aggy
Frequent Advisor

Scripting

I have written a script to enable the account and disable it after the specified days expire, the issue is that many times the support guys just press enter and the script changes the password for the person logged in and running the script; see example below:

/home/tst> ./enable_rw_acct.sh
Please type the user login for read-write access?

For how long user wants access(in days)?

./enable_rw_acct.sh[23]: test: Specify a parameter with this command.
modprpw: user password file not found: bootpw=NO,umaxlntr=-1,llog=-1,acctexp=
Access Granted to
Changing password for root
Old password:

I do not want this to happen and if they do not enter the username or the number of days then the script should exit with some error message

Below is my existing script whcih needs changing:

echo "Please type the user login for read-write access?"
read USERNAME
loginid=`id $USERNAME`
if [[ $loginid = "" ]]
then
echo
#

echo "Please type the user login for read-write access?"
read USERNAME
loginid=`id $USERNAME`
if [[ $loginid = "" ]]
then
echo
echo "Login $loginid does not exists"
echo
echo "Script exiting . . . . ."
exit 0
fi

echo "For how long user wants access(in days)?"
read LENGTH
if [ $LENGTH -ge 15 ]
then
echo "Read-Write access should not exceed 2 weeks.Try again !!!"
exit
else
/usr/lbin/modprpw -l -m bootpw=NO,umaxlntr=-1,llog=-1,acctexp=$LENGTH $U
SERNAME
echo "Access Granted to $USERNAME"

passwd $USERNAME
sleep 1
passwd -f $USERNAME

fi
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: Scripting

Hi Aggy:

One way:

# read REPLY; [ -z "${REPLY}" ] && echo "Empty replies are not allowed!" || echo "ok"

Modify your script appropriately to meet your goals.

Regards!

...JRF...
Aggy
Frequent Advisor

Re: Scripting

Thanks James