Code: Select all
#!/bin/bash
#
# Create a list of Zones for all monitors in /tmp and FTP it to the web
# for safe keeping
#
# Prerequisite: Create $HOME/.netrc, permissions 600 as follows:
#
# machine [insert your webspace upload area here]
# login [insert login name here]
# password [insert password here]
#
# Example $HOME/.netrc follows:
#
# machine users.isp.com
# login george
# password ofthejungle
#
# $HOME/.netrc is used for the ftp at the bottom of the script
#
# Thanks for helping me with the SQL Nugget.
#
# Floyd 13/8/2004
# Your ZM database name
database="[your zm database - probably zm]"
# Your ROOT DB username
rootdb="[username - probably root]"
# Your ROOT DB password
rootpass="[password]"
# Location of local output file
outputlocal="/tmp/Zones.txt"
# Output filename on Webserver
outputweb="Zones.txt"
# Name of Website to FTP to
website="[insert your webspace upload area here]"
# Initialise Local output file
echo "`date`" > $outputlocal
# Run mysql command to extract a callated set of info from the DB to output file
mysql -t -D $database -u "$rootdb" --password="$rootpass" << EOF >> $outputlocal
select M.Name, Z.* from Zones Z
left join Monitors M on Z.MonitorId=M.ID order by Z.MonitorId;
EOF
# Now lets ftp our file to the internet for safe keeping
ftp -v $website << EOF
ascii
put $outputlocal $outputweb
quit
EOF