LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Scripting Help (https://www.linuxquestions.org/questions/linux-newbie-8/scripting-help-4175412496/)

thudpuppy 06-20-2012 11:05 AM

Scripting Help
 
Hello everybody,

I have a script written below that currently will write a single file to an archive that returns an "object ID" to a text file. It works great.

What would be better is if it would write sequential files from a directory i have called "pics", and pass the original filename to associated with the ObjectID to the output file. I'm stuck with this.

Any ideas? Thanks for the help.

___________________________________________________

USERNAME="dee"
TARGET_IP="10.20.30.40"
ARCHIVE_NAME="data1"
SOURCE_FILE="/Users/dee/scripts/image.png"
OUTPUT_FILE="/Users/dee/scripts/output/objectID.txt"
PASSWORD="password"

while true
do
curl -# --tcp-nodelay -u $USERNAME:$PASSWORD -T $SOURCE_FILE -w "Object Size %{size_upload} bytes, Transfer Rate %{speed_upload} bytes/s, Time %{time_total} secs\n\n" http://$TARGET_IP/$ARCHIVE_NAME | tee -a $OUTPUT_FILE
done

pcardout 06-22-2012 02:01 PM

A useful construction to cycle through all files in a directory
 
Hi -- Here is a suggestion for you. I often want to operate on a bunch of files in sequence

Code:

USERNAME="dee"
TARGET_IP="10.20.30.40"
ARCHIVE_NAME="data1"
SOURCE_DIR="/Users/dee/scripts"
OUTPUT_FILE="/Users/dee/scripts/output/objectID.txt"
PASSWORD="password"

cd $SOURCE_DIR
for SOURCE_FILE in `ls *.png` ; do
echo processing $SOURCE_FILE
echo "Your magic goes here ... I don't know curl"
done

What does curl do BTW?
Obviously you can ls whatever you want, including *

pcardout 06-22-2012 02:03 PM

I'll bet you could also do something like

Quote:

for SOURCE_FILE in 'ls *.png | sort' ; do
If you want to operate in alphabetical order and not default directory ls order ... I haven't debugged that ... just pointing it out,
sort is a great linux shell built-in.

grail 06-23-2012 04:21 AM

Please do not use ls in this manner when globbing will not incur the issues you may face. See here for more details.

pcardout 06-23-2012 03:00 PM

grail makes a useful point. Didn't know about the newline issue with ls. I've been using this construction
for years for my own work with no problem, but, by design, I never have filenames with newlines or spaces in them.


All times are GMT -5. The time now is 08:27 PM.