Running a shell command with a keychain

I’m trying to set up a config to launch a shell command every certain amount of times that it is run or until it shows BANNED. I’m struggling to do this and was wondering if I could get some help with it.
Thanks