Very nice use of bash arrays! Could use mput "${FILES[@]}" once the array is populated.<br><br>I saw a blurb somewhere that the backticks were going (are?) to be deprecated. Plus the $() nomenclature allows nesting which can be very handy.<br>
<br><div class="gmail_quote">On Tue, Jan 22, 2013 at 9:06 PM, <span dir="ltr"><<a href="mailto:fletch@phydeaux.org" target="_blank">fletch@phydeaux.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
> Your FILE line is executing a .txt file. I cannot imagine that being<br>
> intentional.<br>
<br>
</div>Yeah I was going to mention all those declarations at the top look fishy<br>
save the cat one (which is fishy for other reasons :).<br>
<br>
The $() quoting is POSIX-ese (I believe) for backticks `` so your date<br>
example is running date and then trying to run the date string that<br>
returns. If you're worried about spaces in filenames or output commands<br>
return you should be using<br>
<br>
FOO="$( some_command --blah)"<br>
<br>
<br>
whereas if you're just wanting to be explicit what you're setting<br>
variables to just use "" or ''<br>
<br>
BAR='/some/path/file.txt'<br>
<br>
<br>
The problem with the cat line is that you're counting the number of lines<br>
in the file before you're recreating it after removing it. Not to mention<br>
you're then checking $FILE == 0 rather than the number of lines that you<br>
put in $FILES (again, prior to recreating it). If you'd just use a single<br>
'>' rather than '>>' the shell would overwrite the existing file and there<br>
wouldn't be a need to remove it beforehand.<br>
<br>
<br>
And I was mistaken in my prior post about perl LWP; it has a mirror sample<br>
but it's a lightweight wget-y thing.<br>
<br>
<br>
Untested (I do zsh, not bash :) but this might be more the direction you'd<br>
want.<br>
<br>
#!/bin/bash<br>
<br>
LOG=/var/log/fl_sdirc<br>
SOURCE_DIR=/chroot/home/fl/fl_sdirc<br>
TIME="$(date '+%m-%d-%Y %H:%M')"<br>
<br>
cd $SOURCE_DIR<br>
<br>
typeset -a FILES<br>
FILES=( $( /bin/ls $SOURCE_DIR ) )<br>
<br>
if [ "${#FILES[@]}" == 0 ] ; then<br>
<div class="im"> echo "$TIME" >> $LOG<br>
echo "No Files tranfer" >> $LOG<br>
else<br>
<br>
</div> for i in "${FILES[@]}" ; do<br>
## Presumes credentials are in ~/.netrc<br>
ftp -i 192.168.105.29 <<"EOT"<br>
binary<br>
put $i<br>
quit<br>
EOT<br>
<div class="im"> done<br>
<br>
echo "$TIME" >> $LOG<br>
echo "File following file were transfer to Pawnee" >> $LOG<br>
<br>
</div> for i in "${FILES[@]}" ; do<br>
echo "$i" >> $LOG<br>
<div class="HOEnZb"><div class="h5"> mv $i /home/fl_sdirc/$i.$TIME<br>
done<br>
<br>
fi<br>
<br>
<br>
<br>
<br>
<br>
> On Jan 22, 2013 12:20 PM, "Chuck Payne" <<a href="mailto:terrorpup@gmail.com">terrorpup@gmail.com</a>> wrote:<br>
><br>
>> Guys,<br>
>><br>
>> Ok, I think I have a better script, but I am having a problem with the<br>
>> for/loop with ftp'ing files, looks like it breaking at the <<+<br>
>><br>
>> Here is my new script<br>
>><br>
>> ========================Begin Script=================================<br>
>><br>
>> #!/bin/bash<br>
>> # ftp script<br>
>> # by Chuck Payne<br>
>> # ftp, logs, and moves files<br>
>><br>
>> LOG=$(/var/log/fl_sdirc)<br>
>> FILES=$(cat /chroot/home/fl/fl_sdirc/files.txt | wc -l)<br>
>> TIME=$(`date '+%m-%d-%Y %H:%M'`)<br>
>> FILE=$(/chroot/home/fl/fl_sdirc/files.txt)<br>
>><br>
>><br>
>> if [ -e $FILE ] ; then<br>
>> rm -f $FILE<br>
>> fi<br>
>><br>
>> ls /chroot/home/fl/fl_sdirc >> /chroot/home/fl/fl_sdirc/files.txt<br>
>><br>
>> if [ $FILE=="0"] ; then<br>
>> echo "$TIME" >> $LOG<br>
>> echo "No Files tranfer" >> $LOG<br>
>> else<br>
>><br>
>> for i in `cat /chroot/home/fl/fl_sdirc/files.txt` ; do<br>
>> ftp -n 192.168.105.29 <<+<br>
>> user flsdir essex<br>
>> binary<br>
>> put $i<br>
>> quit ;<br>
>> done<br>
>><br>
>> echo "$TIME" >> $LOG<br>
>> echo "File following file were transfer to Pawnee" >> $LOG<br>
>><br>
>> for i in `cat /chroot/home/fl/fl_sdirc/files.txt` ; do<br>
>> echo "$i" >> $LOG<br>
>> done<br>
>><br>
>> for i in `cat /chroot/home/fl/fl_sdirc/files.txt` ;<br>
>> mv $i /home/fl_sdirc/$i.$TIME ;<br>
>> done<br>
>><br>
>> fi<br>
>><br>
>><br>
>><br>
>> ========================End Script==================================<br>
>><br>
>><br>
>> --<br>
>> Terror PUP a.k.a<br>
>> Chuck "PUP" Payne<br>
>><br>
>> <a href="tel:%28678%29%20636-9678" value="+16786369678">(678) 636-9678</a><br>
>> -----------------------------------------<br>
>> Discover it! Enjoy it! Share it! openSUSE Linux.<br>
>> -----------------------------------------<br>
>> openSUSE -- <a href="http://en.opensuse.org/User:Terrorpup" target="_blank">en.opensuse.org/User:Terrorpup</a><br>
>> openSUSE Ambassador/openSUSE Member<br>
>> Community Manager -- Southeast Linux Foundation (SELF)<br>
>> skype,twiiter,identica,friendfeed -- terrorpup<br>
>> freenode(irc) --terrorpup/lupinstein<br>
>> Register Linux Userid: 155363<br>
>><br>
>> Have you tried SUSE Studio? Need to create a Live CD, an app you want<br>
>> to package and distribute , or create your own linux distro. Give SUSE<br>
>> Studio a try. <a href="http://www.susestudio.com" target="_blank">www.susestudio.com</a>.<br>
>> See you at Southeast Linux Fest, June 7-9, 2013 in Charlotte, NC.<br>
>> <a href="http://www.southeastlinuxfest.org" target="_blank">www.southeastlinuxfest.org</a><br>
>> _______________________________________________<br>
>> Ale mailing list<br>
>> <a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
>> <a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
>> See JOBS, ANNOUNCE and SCHOOLS lists at<br>
>> <a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
>><br>
> _______________________________________________<br>
> Ale mailing list<br>
> <a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
> <a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
> See JOBS, ANNOUNCE and SCHOOLS lists at<br>
> <a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
><br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Fletch | "If you find my answers frightening, __`'/|<br>
fletch at <a href="http://phydeaux.org" target="_blank">phydeaux.org</a>| Vincent, you should cease askin' \ o.O'<br>
| scary questions." -- Jules =(___)=<br>
</font></span><div class="HOEnZb"><div class="h5"> | U<br>
<br>
<br>
<br>
_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>-- <br>James P. Kinney III<br><i><i><i><i><br></i></i></i></i>Every time you stop a school, you will have to build a jail. What you
gain at one end you lose at the other. It's like feeding a dog on his
own tail. It won't fatten the dog.<br>
- Speech 11/23/1900 Mark Twain<br><i><i><i><i><br><a href="http://electjimkinney.org" target="_blank">http://electjimkinney.org</a><br><a href="http://heretothereideas.blogspot.com/" target="_blank">http://heretothereideas.blogspot.com/</a><br>
</i></i></i></i>