I have devices that I have to FTP to and copy log files from. The log files have 3 generations, that typically roll over every few days. i.e. if I pulled the files down yesterday, I dont want all 3 generations; if it's been a while, I do.
So I have made a script, I expected to be able to pass it a parameter to decide which files to bring down, but it isn't working.
e.g. ". GetLogFiles.sh" will get just the latest generation, ". GetLogFiles.sh a" will get all.
My script looks something like
Code:
#!/bin/sh
HOST='1.2.3.4'
USER='user1'
PASS='password'
FTP='/usr/bin/ftp'
Today="`date +%y%m%d`"
CMD1='get //var//log//messages SiteName_'$Today'.messages.log'
CMD2='get //var//log//messages.0 SiteName_'$Today'.messages.0.log'
CMD3='get //var//log//messages.1 SiteName_'$Today'.messages.1.log'
if [ "$1"!="a" ]; then
echo "Only copying messages, not messages.0 or messages.1"
CMD2=''
CMD3=''
fi
$FTP -n -v $HOST << END_S
quote USER $USER
quote PASS $PASS
hash
$CMD1
$CMD2
$CMD3
END_S
I tired a few variants of
Code:
if [ "$1"!="a" ]; then
if [ $1!="a" ]; then
if ![ $1=="a" ]; then
etc to no avail. At the moment it grabs all files.
Any clues?
Thanks!
Critcho.