FTP Monitor Scripts

These are scripts I use to monitor and FTP site. It's ruff and still needs work but it's operational.

CHECK

#This script written by Will Hughes 3 OCT 03
#This script along with it's associated support scipts
#are designed to ssh or telnet into a remote box,
#do a directory listing, ftp back that listing,
#compare that listing with a default listing, and
#email back a notification if changes have been made.

#Transwestern script ssh's into box, does ls, and ftp's the results back
./transwestern

#Compares the ls results with a defualt set of ls results
#If ls results have changed then it emails vi the notify script
#The file newfile is being used as a flag indicating that a
#file has been recieved. This is to prevent multiple logs of new
#files as well as mutiple email notification.

if diff --brief list list.default
then
if [ -f newfile ]
then
rm -f newfile
echo "`date` File has downloaded" >> status
else
echo "`date`" >> status
fi
else
if [ -f newfile ]
then
echo "`date` File not downloaded" >> status
else
./notify
echo "`date` File Received" >> status
echo "`date` File Received" > newfile
fi
fi

NOTIFY

#!/usr/bin/expect -f
#

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}

set timeout -1
spawn telnet localhost 25
match_max 100000
expect "220 localhost.localdomain ESMTP Sendmail"
send -- "helo will\r"
expect -exact "helo will\r
250 localhost.localdomain Hello tuxbert \[127.0.0.1\], pleased to meet you\r
"
send -- "mail from:tuxbert@williamhughes.net\r"
expect -exact "mail from:tuxbert@williamhughes.net\r
250 2.1.0 tuxbert@williamhughes.net... Sender ok\r
"
send -- "rcpt to:will@aghealth123.com\r"
expect -exact "rcpt to:will@aghealth123.com\r
250 2.1.5 will@aghealth123.com... Recipient ok\r
"
send -- "data\r"
expect -exact "data\r
354 Enter mail, end with \".\" on a line by itself\r
"
send -- "subject:Transwestern file received\r"
expect -exact "subject:Transwestern file received\r
"
send -- "Transwestern file received\r"
expect -exact "Transwestern file received\r
"
send -- ".\r"
expect "Message accepted for delivery\r
"
send -- "quit\r"
expect eof

#!/usr/bin/expect -f
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}

set timeout -1
spawn ssh -l aguser 67.119.161.21
match_max 100000
expect -exact "aguser@67.119.161.21's password: "
send -- "\r"
expect -exact "\r
\[aguser@frs-web aguser\]\$ "
send -- "cd Claim"
expect -exact "im"
send -- "s\r"
expect -exact "s\r
\[aguser@frs-web Claims\]\$ "
send -- "ls > li"
expect -exact "li"
send -- "st\r"
expect -exact "st\r
\[aguser@frs-web Claims\]\$ "
send -- "ftp tuxbert.williamhughes.net"
expect -exact "mhughes.net"
send -- "\r"
expect -exact "\r
Connected to tuxbert.williamhughes.net (67.97.96.8Cool.\r
220 (vsFTPd 1.1.3)\r
Name (tuxbert.williamhughes.net:aguser): "
send -- "will\r"
expect -exact "will\r
331 Please specify the password.\r
Password:"
send -- "\r"
expect -exact "\r
230 Login successful. Have fun.\r
Remote system type is UNIX.\r
Using binary mode to transfer files.\r
\r\rftp> \rftp> "
send -- "c"
expect -exact "\rftp> c\rftp> c"
send -- "d"
expect -exact "\rftp> cd\rftp> cd"
send -- " "
expect -exact "\rftp> cd \rftp> cd "
send -- "t"
expect -exact "\rftp> cd t\rftp> cd t"
send -- "r"
expect -exact "\rftp> cd tr\rftp> cd tr"
send -- "a"
expect -exact "\rftp> cd tra\rftp> cd tra"
send -- "n"
expect -exact "\rftp> cd tran\rftp> cd tran"
send -- "s"
expect -exact "\rftp> cd trans\rftp> cd trans"
send -- "\r"
expect -exact "\r
250 Directory successfully changed.\r
\r\rftp> \rftp> "
send -- "s"
expect -exact "\rftp> s\rftp> s"
send -- "e"
expect -exact "\rftp> se\rftp> se"
send -- "n"
expect -exact "\rftp> sen\rftp> sen"
send -- "d"
expect -exact "\rftp> send\rftp> send"
send -- " "
expect -exact "\rftp> send \rftp> send "
send -- "li"
expect -exact "\rftp> send l\rftp> send l\rftp> send li\rftp> send li"
send -- "s"
expect -exact "\rftp> send lis\rftp> send lis"
send -- "t"
expect -exact "\rftp> send list\rftp> send list"
send -- "\r"
expect ")\r
\r\rftp> \rftp> "
send -- "b"
expect -exact "\rftp> b\rftp> b"
send -- "y"
expect -exact "\rftp> by\rftp> by"
send -- "e"
expect -exact "\rftp> bye\rftp> bye"
send -- "\r"
expect -exact "\r
221 Goodbye.\r
\[aguser@frs-web Claims\]\$ "
send -- "rm list\r"
expect -exact "rm list\r
\[aguser@frs-web Claims\]\$ "
send -- "exit\r"
expect eof