Question : Script to take password automatically

Hello,

I need a Bash script that can execute the following command: "kinit administrator" and take the password "Pass123" automatically (without prompting the user to enter in command line). Incase if the kinit command not accepting the password, or for some reason it fails, I want the script to display the error message in a file.

# kinit administrator
Password for administrator@iihtman:

Thanks

Answer : Script to take password automatically

Okay, this should get you started ... shell version first, with empty-expect (you'd have to install it first, obviously).

http://empty.sourceforge.net/
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
#!/bin/sh
IN=/tmp/in.fifo
OUT=/tmp/out.fifo
 
# fork the kinit process
empty -f -i $IN -o $OUT kinit administrator
# wait to see "@iihtman:", then send "Pass123\n", 
# and timeout after 5 seconds
empty -w -t5 -i $OUT -o $IN "@iihtman:" "Pass123\n"
 
# renew the ticket to verify success
kinit -R #2> /dev/null
if [ $? -eq 0 ]; then
  # do something with valid ticket
  echo Yay
else
  # kerberos auth failed
  echo Boo
fi
 
kdestroy #2> /dev/null
 
rm $IN $OUT > /dev/null 2>&1
Open in New Window Select All
Random Solutions  
 
programming4us programming4us