Every year I have to run a lot of reports for our SOX auditors. And since it is that time again, I figured I would share an example of using for loops to generate reports.
The basic principal is having access to a machine that is able to ssh (no, not telnet) to the machines that need to be queried. Once you have this you can just run a for loop to get the info you need.
Ex.
#!/bin/bash
for m in server1 server2 server3
do
echo "Directory list for $m"
echo "==========================================================="
ssh $m ll -tr /some/directory
done > output.txt
This script would give a long listing of file in /some/directory on server1, server2, and server3. The output would go to output.txt. This simple script could be adjusted to get all kings of information. You could even change the last line to something like this:
done | (mail|mailx) -s "some subject line" me@mydomain.com
Then you would receive the output in your mailbox. Now you could put it in a script and set cron to send you reports.
The basic principal is having access to a machine that is able to ssh (no, not telnet) to the machines that need to be queried. Once you have this you can just run a for loop to get the info you need.
Ex.
#!/bin/bash
for m in server1 server2 server3
do
echo "Directory list for $m"
echo "==========================================================="
ssh $m ll -tr /some/directory
done > output.txt
This script would give a long listing of file in /some/directory on server1, server2, and server3. The output would go to output.txt. This simple script could be adjusted to get all kings of information. You could even change the last line to something like this:
done | (mail|mailx) -s "some subject line" me@mydomain.com
Then you would receive the output in your mailbox. Now you could put it in a script and set cron to send you reports.
Comments
Post a Comment