18

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() { ??? }
NilColor
  • 3,462
  • 3
  • 30
  • 44
anthonybell
  • 5,790
  • 7
  • 42
  • 60

3 Answers3

23

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

tellisnz
  • 548
  • 4
  • 10
1

Try:

klist -s; echo $?

Return 0 if is OK, 1 otherwise

AskerT
  • 11
  • 1
0

I found a solution, but it's a bit of a hack.

if [ `klist 2>&1 | grep -i 'No credentials' | wc -l` -gt 0 ]; then
    kinit
fi
anthonybell
  • 5,790
  • 7
  • 42
  • 60