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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
06-20-2012, 11:05 AM
|
#1
|
LQ Newbie
Registered: Jun 2012
Posts: 1
Rep: 
|
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
|
|
|
06-22-2012, 02:01 PM
|
#2
|
Member
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221
Rep:
|
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 *
|
|
|
06-22-2012, 02:03 PM
|
#3
|
Member
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221
Rep:
|
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.
|
|
|
06-23-2012, 04:21 AM
|
#4
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,040
|
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.
|
06-23-2012, 03:00 PM
|
#5
|
Member
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221
Rep:
|
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 11:20 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|