How to check if you need to throw?

I would like to add something to my .bashrcfile to run kinitif I need it. Is there any way to check if I need to do kinit? Something like that:

if [ kinitNeeded ]; 
    do kinit; 
done

kinitNeeded() { ??? }
+4
source share
2 answers

You can try it klist -s. On the man page:

"causes klist to start silently (it doesn’t give any output), but it still sets the exit status depending on whether it finds the credential cache. The exit status is '0 if klist finds the credential cache, and' 1 if he is not or if the tickets have expired. "

+5
source

I found a solution, but it hacked a bit.

if [ `klist 2>&1 | grep -i 'No credentials' | wc -l` -gt 0 ]; then
    kinit
fi
0

All Articles