It works ("klist -A" shows valid principal):
password="<some_pwd>"
user="karim"
department="JUS"
echo $password | kinit $user@$domain.GOV
Password for [email protected]:
But with the script I got the error:
Enter Password :Password for [email protected]: kinit: Password incorrect while getting initial credentials
*Password for [email protected]: kinit: Password incorrect while getting initial credentials
*Password for [email protected]: kinit: Password incorrect while getting initial credentials
Each password's letter typing leads to the above message.
Script:
#!/bin/bash
password=""
echo "Provide user: "
read user
echo "Provide department's name (JUS, FIN, MIL): "
read department
pass_var="Provide password:"
while IFS= read -p "$pass_var" -r -s -n letter
do
if [[ $letter == $'\0' ]]
then
break
fi
password=password "$letter"
pass_var="*"
if [[ $department == JUS ]];then
echo $password | kinit $user@$department.GOV
fi
done
Also, if user specify the department as JUS, FIN or MIL then the kinit command should be executed with the correct set department. I tried something like that but it does not work:
if [[ $department == JUS || FIN || MIL ]];then
CodePudding user response:
Just fixing obvious errors:
#!/bin/bash
password=""
read -p "Provide username: " user
read -p "Provide department's name (JUS, FIN, MIL): " department
pass_var="Provide password: "
while IFS= read -p "$pass_var" -r -s -n 1 letter
do
if [[ $letter == $'\0' ]]
then
break
fi
password="$password$letter"
pass_var="*"
done
echo
if [[ $department == JUS ]]
then
echo "$password" | kinit "$user@$department.GOV"
fi
You can use a case
or bash's =~
to match departments:
# ...
if [[ $department =~ JUS|FIN|MIL ]]
then
echo ...
fi
# ...
case "$department" in
JUS|FIN|MIL) echo ... ;;
esac