Results 1 to 3 of 3
Forgive the first post, but I rarely ask and usually research, but I'm getting frustrated from my adventures the last couple of hours and thought I'd swallow my pride and ...
- 12-27-2008 #1Just Joined!
- Join Date
- Dec 2008
- Location
- Seattle
- Posts
- 2
Newb: Bash Script, Increase Numerical,
Forgive the first post, but I rarely ask and usually research, but I'm getting frustrated from my adventures the last couple of hours and thought I'd swallow my pride and ask for help.
I am in charge of restoring some text files from an external server I don't have access to. I want to create a script that creates a directory, downloads the text files from the corresponding folder. The task is easy since the text files are numerical so the structure of my task would be:
create folder 001
download "text 1-213.txt"
create folder 002
download "text 1-213.txt"
etc...
How would be the best way to go about this? I've only had a few days experience creating bash scripts so I am a total newb, but I'm having fun learning. Here is what I have so far... a version where I would manually have to copy, paste, and then increase which is completely impracticable because of the size of my task.
But I'd like it to have a structure like-Code:#!/bin/bash mkdir /home/USER/curl/10000 cd /home/USER/curl/10000 curl 'http://SERVER/10000/text[1-213].txt' -O mkdir /home/USER/curl/10001 cd /home/USER/curl/10001 curl 'http://SERVER/10001/text[1-213].txt' -O find . -name "*.txt" -size -4k | xargs rm
Thanks for reading and any help/knowledge is greatly appreciated!Code:#!/bin/bash # mkdir.cd, and URL all increase by 1, but not infinite. ! Or prompt for number range $x=0 mkdir 1000$x (n then + 1) cd 1000$x (n then + 1) curl 'http://SERVER/1000$x(n then + 1)/text[1-213].txt' -O find . -name "*.txt" -size -4k | xargs rm
- 12-27-2008 #2
Play with this script. Notice the contrast between how the single quotes and the double quotes work. It shows you why you want to use double quotes. (But in the very first echo statement, it doesn't make any difference.)
Code:#!/bin/bash echo -n "Enter the top directory number (try 1015, for example) > " read limit thousand=1000; while [[ $thousand -le $limit ]] do echo 'http://SERVER/$thousand/text' echo "http://SERVER/$thousand/text" thousand=$(($thousand+1)) done
--
Bill
Old age and treachery will overcome youth and skill.
- 12-27-2008 #3Just Joined!
- Join Date
- Dec 2008
- Location
- Seattle
- Posts
- 2
Schweet! Definitely something to play with, you're the bestest!


Reply With Quote