I guessed that you folks would want some "code o' my own," so I wrote some.
Did some double-checking on the rules of parameter extraction -- last time I did anything of the kind was in AppleScript three or four years ago.
So here's my script as it stands now. The echos about a correctly-formatted web address are the ones I intend to replace with the cUrl commands.
#!/bin/bash
function whatchagot() {
echo -ne "Where is the file coming from?\n"
read stringZ
dimple=$(echo ${stringZ:0:5})
if [ $dimple != "http:" ]
then
echo -ne "That was not a web address.\n"
echo -ne "I can't fill in your blanks like a web browser can, you know!\n"
else
echo -ne "Very good.\n"
echo -ne "You know what a web address is!\n"
fi
}
echo -ne "What is your file to be called?\n"
read theName
if [ $theName != "done" ]
then
whatchagot
else
echo -ne "Alright. I quit!\n"
fi
I'm taking this one step at a time. I have the function ready, allowing for some substitution of commands. Thanks for the "while true" hint. I'll add your && echo "$NAME" "$LINK" > file.log code later on.
BZT
---------- Post updated 27th Feb 2010 at 13:54 ---------- Previous update was 26th Feb 2010 at 22:42 ----------
Still a little wary of applying the "while true" loop, I made some modifications to the script as last posted, dressing up the output to the log file and making sure that the exit commands were working.
#!/bin/bash
function whatchagot() {
thisFile=$theName
echo -ne "Where is the file?\n"
read thisSource
dimple=$(echo ${thisSource:0:5})
if [ $dimple != "http:" ]
then
echo -ne "I'm exiting.\n"
else
But by avoiding the "while true" loop to this point, I may have hung myself by my own petard, as now, predictably, every time the script is run it creates a new log file with a new date & time as part of the name.
logtime=$(date "+%d.%m.%Y-%H.%M")
logname="curlactivity-$logtime.log"
touch $logname
echo -ne "What is your file to be called?\n"
read theName
if [ $theName != "done" ]
then
whatchagot
else
echo -ne "Alright. I quit!\n"
fi
I like the kind of output I'm getting, nicely formatted etc.:
27.02.2010 @ 13:37:54: tuxubuntu-cute.jpg came from http://www.cogite.info/wallpaper/ and was called Christmas_Tux_Ubuntu_1440-900.jpg
But it looks like I'll have to "dive into the while pool" to make these into real log files instead of "results" redirects with a single string of output to them. Which is not what I meant for them to be.
Would anyone advise abandoning the function part and just bulldozing through, beginning to end, with what I have now? Does that tend to work better when while loops are applied to scripts like this? Or am I asking two incompatible questions?
BZT
My complete script as of this post time:
#!/bin/bash
function whatchagot() {
thisFile=$theName
echo -ne "Where is the file?\n"
read thisSource
dimple=$(echo ${thisSource:0:5})
if [ $dimple != "http:" ]
then
echo -ne "I'm exiting.\n"
else
GRABTIME=$(date "+%d.%m.%Y @ %H:%M:%S")
thisPlace=`echo $thisSource | rev | cut -d / -f2- | rev`
thisName=`echo ${thisSource##*/}`
curl -o "$thisFile" "$thisSource" && echo -ne "$GRABTIME": "$thisFile" came from "$thisPlace/" and was called "$thisName\n">> $logname
fi
}
logtime=$(date "+%d.%m.%Y-%H.%M")
logname="curlactivity-$logtime.log"
touch $logname
echo -ne "What is your file to be called?\n"
read theName
if [ $theName != "done" ]
then
whatchagot
else
echo -ne "Alright. I quit!\n"
fi