cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2313
Views
5
Helpful
19
Replies

Using EEM & tcl script to talk to a remote http server

thinkingphones
Level 1
Level 1

I would like to use the eem and a tcl script to check for any new files to download from a remote http server. The eem would be used as a scheduler to invoke the tcl script - which would access the http server and download any new files (what will be ip phone config files) to the flash on the router.

Can anyone provide me with an example config for this?

thanks,

John.

19 Replies 19

Joe Clarke
Cisco Employee
Cisco Employee

First, you should not be using EEM to execute a tclsh script. Instead, you should do everything in an EEM Tcl policy. Second, on what version of IOS will this policy run? If you already have the tclsh script to do the HTTP operations, please post that.

yjdabear
VIP Alumni
VIP Alumni

There is already HTTP code built-in to EEM. that is why I asked about IOS version and whether or not he had existing code to do his HTTP operations.

Could you list the minimum version of EEM/IOS required to get built-in http get support?

I am running IOS version 12.4(15)T9 on an IAD 2431 router. I have not written the http get code yet.

thanks,

John.

This should do what you want. It requires three environment variables to be set (examples below):

event manager environment http_check_time 86400

event manager environment http_check_url http://host.company.com/file.txt

event manager environment http_check_fs flash:

The above will run the script every 24 hours, download file.txt from the given host, and save the file to flash:/file.txt.

Thanks. I added the following to my config:

event manager environment http_check_url http://10.10.10.10/conf/test-tcl/file1.txt

event manager environment http_check_fs flash:

event manager environment http_check_time 60

event manager directory user policy "flash:/"

event manager policy tm_http_check.tcl

but saw the following in the debug:

%HA_EM-6-LOG: tm_http_check.tcl: "open flash: /file1.txt w"

%HA_EM-6-LOG: tm_http_check.tcl: Tcl policy execute failed: expected integer but got "w"

Any idea what might be wrong? (I set it to check every 60 secs just for testing)

thanks,

John.

Did you modify my script any? It looks like something might have been changed.

I didn't modify it... I see there was a "w" at the end of this line:

set fd [open "${http_check_fs}/${fname}" "w"]

So i removed that... now when i run it i get what looks like a permissions error:

002067: .Aug 4 16:23:47.590: %HA_EM-6-LOG: tm_http_check.tcl: invalid access mode "/file1.txt": must be RDONLY, WRONLY, RDWR, APPEND, CREAT EXCL, NOCTTY, NONBLOCK, or TRUNC

The line should read:

set fd [open "${http_check_fs}/${fname}" "w"]

It could be that the file name is being found with an embedded space. Can you post an attachment of the device config and output (copied from the terminal), so I can check?

Config and debug attached.

thanks,

John.

Try this version.

Thanks - the new script seems to be working. What was different? I diff'd the files - but didn't see anything.

Your script requires that you must enter a filename for the http_check_url variable. How much harder would it be to have it download all the contents of a directory? Or just the files that have changed since the last download?

The new script trims whitespace from the environment variables.

Loading all files in a directory over HTTP is non-trivial since you can't do a directory listing over HTTP. The way indexing works is that the web server generates an HTML page which lists the directory contents. Therefore, the client would need to parse the HTML data returns for the directory, and then make new HTTP requests for each file. This is doable, but as I said, it's not as trivial as doing this with a regular directory.

An alternative would be to tar up all of the files you want to download, then have the client download the tar file. IOS can easily work with tar files. You can then call the IOS archive command to extract the file. The new config files can be copied from a temp location to the final destination.

Clearly the latter method is the easiest.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: