[ale] FTP files

fletch at phydeaux.org fletch at phydeaux.org
Tue Jan 22 21:06:46 EST 2013


> Your FILE line is executing a .txt file. I cannot imagine that being
> intentional.

Yeah I was going to mention all those declarations at the top look fishy
save the cat one (which is fishy for other reasons :).

The $() quoting is POSIX-ese (I believe) for backticks `` so your date
example is running date and then trying to run the date string that
returns.  If you're worried about spaces in filenames or output commands
return you should be using

FOO="$( some_command --blah)"


whereas if you're just wanting to be explicit what you're setting
variables to just use "" or ''

BAR='/some/path/file.txt'


The problem with the cat line is that you're counting the number of lines
in the file before you're recreating it after removing it.  Not to mention
you're then checking $FILE == 0 rather than the number of lines that you
put in $FILES (again, prior to recreating it).  If you'd just use a single
'>' rather than '>>' the shell would overwrite the existing file and there
wouldn't be a need to remove it beforehand.


And I was mistaken in my prior post about perl LWP; it has a mirror sample
but it's a lightweight wget-y thing.


Untested (I do zsh, not bash :) but this might be more the direction you'd
want.

#!/bin/bash

LOG=/var/log/fl_sdirc
SOURCE_DIR=/chroot/home/fl/fl_sdirc
TIME="$(date '+%m-%d-%Y %H:%M')"

cd $SOURCE_DIR

typeset -a FILES
FILES=( $( /bin/ls $SOURCE_DIR ) )

if [ "${#FILES[@]}" == 0 ] ; then
  echo "$TIME" >> $LOG
  echo "No Files tranfer" >> $LOG
else

  for i in "${FILES[@]}" ; do
    ## Presumes credentials are in ~/.netrc
    ftp -i 192.168.105.29 <<"EOT"
binary
put $i
quit
EOT
  done

  echo "$TIME" >> $LOG
  echo "File following file were transfer to Pawnee" >> $LOG

  for i in "${FILES[@]}" ; do
    echo "$i" >> $LOG
    mv $i /home/fl_sdirc/$i.$TIME
  done

fi





> On Jan 22, 2013 12:20 PM, "Chuck Payne" <terrorpup at gmail.com> wrote:
>
>> Guys,
>>
>> Ok, I think I have a better script, but I am having a problem with the
>> for/loop with ftp'ing files, looks like it breaking at the <<+
>>
>> Here is my new script
>>
>> ========================Begin Script=================================
>>
>> #!/bin/bash
>> # ftp script
>> # by Chuck Payne
>> # ftp, logs, and moves files
>>
>> LOG=$(/var/log/fl_sdirc)
>> FILES=$(cat /chroot/home/fl/fl_sdirc/files.txt | wc -l)
>> TIME=$(`date '+%m-%d-%Y %H:%M'`)
>> FILE=$(/chroot/home/fl/fl_sdirc/files.txt)
>>
>>
>> if [ -e $FILE ] ; then
>>   rm -f $FILE
>> fi
>>
>> ls /chroot/home/fl/fl_sdirc >> /chroot/home/fl/fl_sdirc/files.txt
>>
>> if [ $FILE=="0"] ; then
>>   echo "$TIME" >> $LOG
>>   echo "No Files tranfer" >> $LOG
>> else
>>
>> for i in `cat /chroot/home/fl/fl_sdirc/files.txt` ; do
>>   ftp -n 192.168.105.29 <<+
>>   user flsdir essex
>>   binary
>>   put $i
>>   quit ;
>> done
>>
>> echo "$TIME" >> $LOG
>> echo "File following file were transfer to Pawnee" >> $LOG
>>
>> for i in `cat /chroot/home/fl/fl_sdirc/files.txt` ; do
>>   echo "$i" >> $LOG
>> done
>>
>> for i in `cat /chroot/home/fl/fl_sdirc/files.txt` ;
>>   mv $i /home/fl_sdirc/$i.$TIME ;
>> done
>>
>> fi
>>
>>
>>
>> ========================End Script==================================
>>
>>
>> --
>> Terror PUP a.k.a
>> Chuck "PUP" Payne
>>
>> (678) 636-9678
>> -----------------------------------------
>> Discover it! Enjoy it! Share it! openSUSE Linux.
>> -----------------------------------------
>> openSUSE -- en.opensuse.org/User:Terrorpup
>> openSUSE Ambassador/openSUSE Member
>> Community Manager -- Southeast Linux Foundation (SELF)
>> skype,twiiter,identica,friendfeed -- terrorpup
>> freenode(irc) --terrorpup/lupinstein
>> Register Linux Userid: 155363
>>
>> Have you tried SUSE Studio? Need to create a Live CD,  an app you want
>> to package and distribute , or create your own linux distro. Give SUSE
>> Studio a try. www.susestudio.com.
>> See you at Southeast Linux Fest, June 7-9, 2013 in Charlotte, NC.
>> www.southeastlinuxfest.org
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>


-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org|  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U





More information about the Ale mailing list