08-03-2009 10:48 AM
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.
08-03-2009 11:14 AM
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.
08-03-2009 11:17 AM
An example of cron-like EEM scheduler was given in this old thread.
I can't think of what to use to perform "http get" though.
08-03-2009 11:23 AM
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.
08-03-2009 11:33 AM
Could you list the minimum version of EEM/IOS required to get built-in http get support?
08-03-2009 11:43 AM
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.
08-03-2009 01:28 PM
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.
08-04-2009 12:04 PM
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.
08-04-2009 12:08 PM
Did you modify my script any? It looks like something might have been changed.
08-04-2009 12:25 PM
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
08-04-2009 01:06 PM
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?
08-04-2009 01:30 PM
08-04-2009 01:46 PM
08-04-2009 06:57 PM
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?
08-04-2009 08:28 PM
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide