Results 1 to 3 of 3
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 ...
- 09-30-2008 #1Just Joined!
- Join Date
- Sep 2008
- Posts
- 2
Conditional (IF) test in bash sh script - presence of first parameter
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
I tired a few variants ofCode:#!/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
etc to no avail. At the moment it grabs all files.Code:if [ "$1"!="a" ]; then if [ $1!="a" ]; then if ![ $1=="a" ]; then
Any clues?
Thanks!
Critcho.
- 09-30-2008 #2Just Joined!
- Join Date
- Sep 2008
- Posts
- 2
Question was answered on another forum, reposted here to help anyone else who has the same problem:
I needed spaces either side of my condition:
now it works... Painfully simply but elusive...!Code:if [ "$1" != "a" ]; then
- 09-30-2008 #3
Glad you got it fixed -- it was torturing me!!!
Welcome to the forums!Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode


Reply With Quote