realdannys realdannys - 1 month ago 10
Bash Question

Retry command line in bash script until successful then continue with script

Hopefully someone must know this one and I can answer my other question. Launchagent attempts to load my script too quickly and thus it fails - I've set its nice to 20 and everything else to the end but still, when creating accounts its too quick.

The script invokes

cliclick
which fails if the system is not properly logged in as an unknown command. So, my idea is this.

At the start of the script run
cliclick -h
which displays the help menu. If it fails on command unknown, keep repeating until it succeeds at which point carry on with the rest of the script.

Its a dirty method of making sure the script doesn't run until the user is at desktop and I can't think of a better one, but I also don't know how to implement it - so bash scripting gurus, how can I loop "cliclick -h" until its successful then continue with the rest of the script?

Answer Source

Try out this tool: https://github.com/kadwanev/retry

retry -t 1000 -e cliclick -h

check exit code to see if it succeeded at all after all retries...