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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi all
Basically, I want to have a script, that runs wget to download and backup some files off my webserver.
I've been trying to "add" a number and run it in a loop, but unfortunately, the leading zero's were gone after that.
This is the script, that should be run:
# !/bin/sh
# Backup files from webserver
#echo backing up files..
NUMBER="0001"
echo wget "h**p://shadow/edata/ed"$NUMBER".inf" (can't post the url due to forum restrictions)
The next file, it should try to get via wget is 0002, 0003, 0004, you get the point the file range is currently 0001 - 0250..
Would any of you have an idea of how to get that up and running?
This is a quick and dirty (very dirty) way of doing it:
Code:
#!/bin/bash
NUMBER=1
while [ $NUMBER lt 251 ]; do #This will do our counting
while [ `echo $NUMBER | wc -c` lt 5 ]; do #This adds 0's to the beginning of the number until it's 4 characters in length, I hope.
let NUMBER=0$NUMBER
done
wget http://shadow/edata/ed{$NUMBER}.inf
let NUMBER += 1 #increment
done
#EOF
I think this should work, but to be safe, add 'echo' before the wget statement to see if it gives the right results... I don't have a box on which I can test it right now.
Thank you very much for your fast reply!
When I tried to execute the script, I got an "lt: binary operator expected" error in line 3, so I changed the lt to -lt.
I then got an error in line 8. After a google search, I added the quotation marks, that works fine as well now
When running the script now, I get following output:
./backup: line 4: [: +lt: binary operator expected
wget h**p://shadow/edata/ed{241}.inf <- (it's counting up from 1 to 250 okay, seems like the {} are not needed).
But when I change the lt in line4 to -lt, nothing happens, the script just hangs...
Getting very close
this is the current script:
Code:
#!/bin/bash
NUMBER=1
while [ $NUMBER -lt 251 ]; do #This will do our counting
while [ `echo $NUMBER | wc -c` lt 5 ]; do #This adds 0's to the beginning of the number until it's 4 characters in length, I hope.
let NUMBER=0$NUMBER
done
echo wget h**p://shadow/edata/ed{$NUMBER}.inf
let "NUMBER += 1" #increment
done
#EOF
Incidentally, in the bash version, you've only converted the 1st instance of 'lt' => '-lt'. you need to do the same to the 2nd instance, which funnily enough is line 4 (!) as per the error msg...
I did not see the posts from yesterday, so I sat down with a friend of mine and analyzed the script, and we got it working
if anyone is interested, here it is:
Code:
#!/bin/bash
NUMBER=1
while [ $NUMBER -lt 251 ]; do #This will do our counting
COUNTER=$NUMBER
while [ `echo $COUNTER | wc -c` -lt 5 ]; do #This adds 0's to the beginning of the number until it's 4 characters in length, I hope.
export COUNTER="0"$COUNTER
done
wget http://shadow/edata/ed$NUMBER.inf
let "NUMBER += 1" #increment
done
#EOF
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.