[Solved] Get files & delete them by shell script

I want to use my script to get any file then delete it once it transfers to my side , I manage to create below script to generate "list" file which contains all file names in "10.10.1.1" then I made "a.out" file which contains the commands that I want to run it on "10.10.1.1" to get & delete the files , I feel my script still miss some statement as I tried to pass "a.out" to ftp command but went wrong , what I should do to automate my script in order to get the files & delete them as well ?

#!/usr/bin/ksh
ftp -in 10.10.1.1 << EOF 
user  ftpuser ftppass
cd /user/path
bin
dir  *.dat   ./list
bye
EOF

awk '{print $NF}'   ./list | while read file; do
echo "ftp -in 10.10.1.1
user  ftpuser ftppass
bin
cd /user/path
get $file
del $file
bye" >>  a.out
done

Just remove the code echo " and " >> a.out and your loop should process them all.

If you are concenerned by the del during testing, you could just issue a dir of the file instead.

I hope that this helps,

Robin
Liverpool/Blackburn
UK

1 Like

Dear rbatte1

you are right I just remove the echo & do some modification for "here document" then it succeeded .. thanks a lot ...