I am using few shell scripts to keep an eye on some important services on a windows box. Other solutions have proven to be unreliable (BigBrother decides it's not going to send an email on at a critical moment, automation on the windows box fails to run, etc). I, unfortunately, am not in a position where I can make changes to the windows box or BigBrother (if I was it would be a Linux Box and I would not have this problem).
First up, I am monitoring a number of services. The command is easy enough
Code:
net rpc service status servicename -I server -U user@domain%password
Even pass it though awk to give me a simple "ServiceName service is running / stopped / etc". However, this command has flaws. It has a one out of five chance to return the following:
Code:
Could not connect to server ###.###.###.###
Connection failed: NT_STATUS_BAD_NETWORK_NAME
However, if I try the command again, it works fine with no issues.
Here is my question: is there a way to suppress the error message and simply display output when it successfully runs? Secondly when it fails is there a way to make it run up to 5 times until success or and print a custom error message when it fails all 5 or 3 out of the 5 or something along those lines? Thank you for the input