So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other servers.
After getting all the 3 files in my local server, i am appending all 3 into a master file.
Is there a way to directly output result of script in remote server to a file in my local server and keep appending for other remote servers?
Content of Script1:
zcat /logs/jvm1/Audit.log.gz | grep 'Exception' >/tmp/AuditlogServer1.txt
scp /tmp/AuditlogServer1.txt userid@server1:/tmp/
fi
This worked perfect. Thanks. I have another query.
Suppose one of the servers does not have the file Audit.log.gz present , the script skips that server with an error message "Audit.log.gz not found" . How Can i log that error message and the corresponding server in another text file ?
Redirect stderr to another text file to capture the err msg. If you need the server as well, you have to take care of that in your script, e.g. echo the server name to stderr if an exit code is not zero.