I would like to add something to my .bashrc
file to run a kinit
if I need one. Is there a way to test if I need to do a kinit
? Something like this:
if [ kinitNeeded ];
do kinit;
done
kinitNeeded() { ??? }
You could try klist -s . From the man page: "causes klist to run silently (produce no output), but to still set the exit status according to whether it finds the credentials cache. The exit status is '0' if klist finds a credentials cache, and '1' if it does not or if the tickets are expired."
kinit is used to obtain and cache Kerberos ticket-granting tickets.
To use Kerberos List to view tickets, you must run the tool on a computer that's a member of a Kerberos realm. When Kerberos List is run from a client, it shows the following: Ticket-granting ticket (TGT) to a Kerberos Key Distribution Center (KDC) in Windows. Ticket-granting ticket (TGT) to Ksserver on UNIX.
To confirm that the ticket is expired, run the klist command. This command checks for a credentials cache. If no credentials are cached, then the ticket is expired.
You could try klist -s
. From the man page:
"causes klist to run silently (produce no output), but to still set the exit status according to whether it finds the credentials cache. The exit status is ‘0’ if klist finds a credentials cache, and ‘1’ if it does not or if the tickets are expired."
Try:
klist -s; echo $?
Return 0
if is OK, 1
otherwise
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With