Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test if a kinit is needed?

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() { ??? }
like image 732
anthonybell Avatar asked May 16 '16 18:05

anthonybell


People also ask

How do you know your Kinit?

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."

Why is Kinit used?

kinit is used to obtain and cache Kerberos ticket-granting tickets.

How do I check my Kerberos status?

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.

How do I know if my Kerberos ticket is expired?

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.


2 Answers

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."

like image 76
tellisnz Avatar answered Nov 07 '22 09:11

tellisnz


Try:

klist -s; echo $?

Return 0 if is OK, 1 otherwise

like image 34
AskerT Avatar answered Nov 07 '22 09:11

AskerT