<?xml version="1.0" encoding="Big5" ?>
<project name="backup" default="cisco" basedir=".">
<description>Network Switch Config Backup</description>
<!-- Enable access to build.properties variables -->
<property file="build.properties" />
<property name="backup.root.dir" value="/root/cisco" />
<property name="cisco.backup.dir" value="${backup.root.dir}/${cisco.ip}" />
<property name="tftp.root" value="/tftpboot" />
<!-- Init -->
<target name="init" description="Create backup directory">
<tstamp>
<format property="TODAY" pattern="yyyyMMdd" />
</tstamp>
<property name="cisco.cfg" value="cisco_${TODAY}.cfg" />
<mkdir dir="${backup.root.dir}" />
<mkdir dir="${backup.root.dir}/${cisco.ip}" />
<touch file="${tftp.root}/${cisco.cfg}"/>
<chmod file="${tftp.root}/${cisco.cfg}" perm="ugo+rwx"/>
</target>
<!-- Backup cisco Config -->
<target name="cisco" depends="init" description="Backup cisco config">
<property name="cisco.cfg" value="cisco_${TODAY}.cfg" />
<telnet server="${cisco.ip}">
<read timeout="5">Username: </read>
<write>${cisco.username}</write>
<read timeout="5">Password: </read>
<write>${cisco.password}</write>
<read timeout="5">></read>
<write>enable</write>
<read timeout="5">Password: </read>
<write>${enable.password}</write>
<read timeout="5">#</read>
<write>copy startup-config tftp://${tftp.host}/${cisco.cfg}</write>
<read timeout="30">Address or name of remote host [${tftp.host}]?</read>
<write>${tftp.host}</write>
<read timeout="30">Destination filename [${cisco.cfg}]?</read>
<write>${cisco.cfg}</write>
<read timeout="30">bytes/sec)</read>
<write>exit</write>
</telnet>
<move file="${tftp.root}/${cisco.cfg}" todir="${cisco.backup.dir}" />
</target>
</project>
tftp.host=172.16.38.1
cisco.ip=172.16.38.254
cisco.username=admin
cisco.password=admin
enable.password=cisco
#!/bin/bash
ANT_HOME=/root/cisco/apache-ant-1.7.1
JAVA_HOME=/usr/java/latest
PATH=$PATH:$ANT_HOME/bin:$JAVA_HOME/bin
ant cisco