Shell Scripting: Suppress error / Best 3 out of 5
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 Code:
Could not connect to server ###.###.###.### 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 |
Here is what you can try:
Code:
net rpc service status servicename -I server -U user@domain%password 2&>1 /dev/null |
Dump the output into a variable and use the exit status to determine what to do with it (or whether to run it again)
Code:
num=0 |
In the first example I get no output. The script shows all output being sent to /dev/null
In the second example I had to add a space after 5 and before ]] to get it to run. However, it still shows the error message. Am I missing something? do I need to put the output though ack, awk or something similar? |
Put a "2>&1" at the end of the net command to redirect stderr to stdout.
|
Hi,
To supress the error output, but keep the standard output redirect stderr (2) to /dev/null so shown below. This ensures that "output" will only contain the words you want to see! cheers pete pete hilton saruman@ruvolo-hilton.org Code:
num=0 |
All times are GMT -5. The time now is 02:22 PM. |