LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-20-2012, 11:05 AM   #1
thudpuppy
LQ Newbie
 
Registered: Jun 2012
Posts: 1

Rep: Reputation: Disabled
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
 
Old 06-22-2012, 02:01 PM   #2
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("lenny", "squeeze"), Ubuntu ("karmic", "oneiric")
Posts: 214

Rep: Reputation: 24
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 *
 
Old 06-22-2012, 02:03 PM   #3
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("lenny", "squeeze"), Ubuntu ("karmic", "oneiric")
Posts: 214

Rep: Reputation: 24
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.
 
Old 06-23-2012, 04:21 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,564

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
Please do not use ls in this manner when globbing will not incur the issues you may face. See here for more details.
 
1 members found this post helpful.
Old 06-23-2012, 03:00 PM   #5
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("lenny", "squeeze"), Ubuntu ("karmic", "oneiric")
Posts: 214

Rep: Reputation: 24
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 10:09 PM
Help with scripting guptneelam Linux - Newbie 3 03-06-2009 06:23 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
HELP!! with scripting eggoz Linux - General 1 04-25-2003 07:52 PM


All times are GMT -5. The time now is 04:59 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration