"Automater"
Tech Tip: Running Scripts From MS Windows Scheduler
In some cases you may want to have a script scheduled to run
unattended at specific time.
An example may be backing up IOS configurations on a nightly or
weekly basis or running the pinger script to verify any-to-any
connectivity. The pinger script can also be configured to only
confirm connectivity between several critical locations in the
network. Here, you may want to run this script more
frequently, perhaps every 15 or 30 minutes.
This tech tip will explain the configuration steps needed to run
a script from a Microsoft Windows system using the Windows Scheduler
Utility. (Note, the trial version will not work
with Windows Scheduler). The example used for demonstration purposes will
be backing up router configurations every Saturday at 2:00 AM. It is assumed the end user installation steps at
the beginning of the User's Manual were performed. This
example also assumes the user's script directory is
C:\Program Files\Net-Sense\.
The easiest way to accomplish this is to put the command line
version, of a particular script, in a windows batch file. Then, just call
the batch file from the MS windows scheduler utility.
First, you will need to have a login/password file configured to
store login and password information. (See the User's Manual for
more on the login/password file). If this is a production
environment, it is highly recommended that the login/password file
first be encrypted using the encrypt_logins utility/script. When
encrypting a login/password file that will be used with scheduler, you
must use the -nokey option. You can run the encrypt_logins
utility from the GUI or the comamnd line.
Below shows the batch file to backup the router configs using
tftp. This batch file should be stored in the C:\Program
Files\Net-Sense\userdata directory so that relative path
names can be used on the command line. (Note, be sure to
create this in text only formatting using an application such as
Windows Notepad). We'll call the name of this file
config_backup.bat (any filename ending in .bat will do). (Note, the script name
[copy_to_tftp] and the
arguments must all be on a single line when creating this file).
for /f "tokens=2-4 delims=/ " %%a in
('date /t') do (set date=%%a%%b%%c)
copy_to_tftp -log scheduler_logs\copy_to_tftp_%date%.log -pw
encr_logins.txt -rf routers.txt -ipaddr 10.1.1.1 -subdir rtr_configs\%date%
-tftproot c:\tftpdir -nokey
Here are some more details about the script arguments being used:
 | -log scheduler_logs\copy_to_tftp_%date%.log
This is the detailed trace filename. Note, the -log
argument is optional but in this case the log file would get
overwritten for each subsequent run if we did not use this
argument. The %date% will get
replaced with the date (mmddyy) as set in the for loop. |
 | -pw encr_logins.var This is the name of the
login/password file. Note, here it is encrypted. (File
location: C:\Program Files\Net-Sense\userdata)
|
 | -rf routers.rt The file routers.rt
contains a list of routers or IP Addresses. One Router/IP
Addresses per line. If the router name its defined in DNS or
/etc/hosts file, then the name can be used in this file.
(File location: C:\Program Files\Net-Sense\userdata) |
 | -ipaddr 10.1.1.1 This is the IP Address of
the TFTP server. In this case, the system running the script
must also be the TFTP server. This is always the case when
the script is using the arguments to create directories and
"touch" a blank file. (Put in your IP addresses) |
 | -subdir rtr_configs\%date% This is the sub-directory, under
the default TFTP directory, that the configs will be saved to.
Each day the script is run, a new directory will be created so the
older config files are not over written. |
 | -tftproot c:\tftpdir This is the default TFTP
directory configured on the system. Note, your system may
have a different default TFTP server directory name than /tftpdir. |
 | -nokey This is needed because the
login/password file (logins.var) was encrypted which would
normally result in the user be prompted for an encryption key.
Using this option tells the script not to prompt for an encryption
key. Remember, you must create the encrypted login/password
file with the -nokey option, in order to use this option in a
script. |