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() { ??? }
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."
Try:
klist -s; echo $?
Return 0
if is OK, 1
otherwise
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