Running CLI commands remotely using Perl - Jan 2014
Tutorial by rosie
This is going to be a pretty straight forward tutorial for getting the results of the previous days logins from the audit-trail command from the controller via a perl script.
This script is running on an Ubuntu machine and the controller is a 7240 running 18.104.22.168 with enable bypass configured.
You will need to set the host, username and password variables so they coincide with your controller and then set the array @CmdList to the commands that you want to run. The commands I have set are "no paging" so that we can get the complete results of the next command that I have set which is "show audit-trail login | include \"$date\"" which in this case we show the audit-trail for the previous day. The $date variable using the *nix date command to get the current date and subtract one day from it then store that result into $date. It works great when going from say the 1st of one month to the 31st of the previous month without having to do any of the extra work.
This script can be adapted to run many different commands and it can be used to connect to all types of devices/servers that accept SSH connections.
- Save the attached file into a directory on your Ubuntu machine, I'll put it in /scripts/aruba and call it getDailyAudit.pl
- Open the file in your favorite text editor
- Set the host, username and password variables
- Set the array @CmdList to have the commands you want to run on the server (separated by commas)
- Run the following command from the terminal: sudo perl /scripts/aruba/getDailyAudit.pl
I hope this helps some of you who are looking to modify some of the regular tasks that are performed from the CLI. If you are looking for some ideas: I use a variation of this script to get results, copy them to a file and then I use additional grep statements to further narrow down the results and email the results daily/weekly to our audit analysts.
Have fun, post any ideas or custom scripts you've written using this tutorial as a base and please don't forget to Kudo if this has helped.
Install Ubuntu: http://www.ubuntu.com/download/desktop/install-desktop-latest