Mobility Hero Tutorials

Running CLI commands remotely using Perl - Jan 2014

Super Contributor II

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 6.3.1.1 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.

 

Script attached:

 

  1. Save the attached file into a directory on your Ubuntu machine, I'll put it in  /scripts/aruba and call it getDailyAudit.pl
  2. Open the file in your favorite text editor
  3. Set the host, username and password variables
  4. Set the array @CmdList to have the commands you want to run on the server (separated by commas)
  5. Run the following command from the terminal: sudo perl /scripts/aruba/getDailyAudit.pl
  6. Profit

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.

 

 

Reference:

Install Ubuntu: http://www.ubuntu.com/download/desktop/install-desktop-latest

Net:Smiley FrustratedSH:Expect http://search.cpan.org/~bnegrao/Net-SSH-Expect-1.09/lib/Net/SSH/Expect.pod

Version history
Revision #:
1 of 1
Last update:
‎02-26-2014 08:15 AM
Updated by:
 
Labels (2)
Contributors
Tags (1)
Comments

I see no attached script.

mohler@graceland.edu

I would be interested in looking at this script - if it was attached.

Search Airheads
cancel
Showing results for 
Search instead for 
Did you mean: