ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
for c in $( echo ${ISO} )
do
if [ -f ${ZONEROOT}/${c}.zone]; then
test $(date -d "-1 week" +%s) -lt $(stat -c "%Y" ${ZONEROOT}/${c}.zone)
printf "Zone files are up to date. Less than 1 week old."
elif
test $(date -d "+1 week" +%s) -lt $(stat -c "%Y" ${ZONEROOT}/${c}.zone)
printf "Zone files are out of date. Updating." ; then
${GET} -Nr ${ZONEROOT} ${DLROOT}/${c}.zone
else
${MKD} -p
${GET} -Nr ${ZONEROOT} ${DLROOT}/${c}.zone
fi
done
P.S: Wrap your variables in curly brackets whenever you get a chance. That cuts down on the shell's chance to get confused.
P.P.S: If this script runs as root, you might want to consider using the absolute path to any binaries you call.
Jokers tend to leave little scripts in a filesystem named "ls" that contain "rm -rf $@"
Last edited by xeleema; 05-02-2011 at 01:34 AM.
Reason: Because I have a sense of humor.
Well the joker would be a douche wouldnt he. I mean to wipe a directory like that on someone. Any way.
So, could you tell me why the if, then, else statements are working? For some reason when conditions in if are not met, the script still runs as if they had been met. See below:
Code:
./Documents/new.set.script.sh: 73: [-f: not found
stat: cannot stat `/etc/firewall/zones/kr.zone': No such file or directory
test: 73: -lt: argument expected
Zone files are out of date. Updating./etc/firewall/zones: Scheme missing.
--2011-05-02 02:28:51-- http://www.ipdeny.com/ipblocks/data/countries/kr.zone
Resolving www.ipdeny.com... 64.85.170.117
Connecting to www.ipdeny.com|64.85.170.117|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13909 (14K) [text/plain]
Server file no newer than local file `www.ipdeny.com/ipblocks/data/countries/kr.zone' -- not retrieving.
I thought that ifr the file had not been found at $ZONEROOT, else would take over and build the directory/file. No? Also, what does this mean:
Code:
test: 73: -lt: argument expected
Zone files are out of date. Updating./etc/firewall/zones: Scheme missing.
P.S: Wrap your variables in curly brackets whenever you get a chance. That cuts down on the shell's chance to get confused.
P.P.S: If this script runs as root, you might want to consider using the absolute path to any binaries you call.
Jokers tend to leave little scripts in a filesystem named "ls" that contain "rm -rf $@"
It's not the shell that gets confused -- it's the programmer! It is a matter of personal preference but I find using braces (curly brackets) makes the code more cluttered and hence harder to understand so I use them only when necessary -- that is when doing expansions and when the following character could be part of the variable name, for example echo "${animal}s are living critters"
The problem with absolute paths is they are not portable across systems that have executables in different directories. One solution is to put the names in variables (for example ls=/bin/ls) so they can be changed in one place. That's still cumbersome and requires modifying the script to work on a variety of systems. Perhaps the best solution (for security and to set up a defined shell execution environment) is for the script to set its own PATH, for example export PATH=/usr/bin:/bin
well all i want to do is create a folder with some files in it. Why does the script continue to elif in my script if the folder /etc/firewall does not exist? I thought thats what the starting if statement was looking for. if [-f some.file] is not found, then what ever commands are under else would be ran. No?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.