|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi, I need a help. I used this command to list all the log files which are for more than 10 days to a text file. Code:
find /usr/script_test -type f -mtime +10>>/usr/ftprm.txt I want all these files listed in the ftprm.txt to be ftp in another machine and then rm the files. Anyone can help me out. am new in scripting. Thanks Last edited by Scrutinizer; 01-04-2013 at 02:58 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
while read filename
do
#ftp code goes here..
rm ${filename}
done < /usr/ftprm.txtftp code (use mput method - instead of mget ) http://www.unix.com/shell-programmin...tp-server.html |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks for the reply. but its not working. am thinking how the ftp will know from which directory to take the files and ftp. please find code which am using: Code:
while read filename
do
ftp -i -n << EOF
open 192.168.1.75
user loguser PASSWORD
prompt
cd \logs_finacle
mput *.*
EOF
rm ${filename}
done < /usr/ftprm.txtLast edited by Scrutinizer; 01-04-2013 at 08:50 AM.. Reason: code tags |
|
#4
|
|||
|
|||
|
kamaldev, itkamaraj has drawn you the skeleton of a solution. You will need to ftp one file at a time with the loop. If you test that the file has been delivered successfully, then you can remove it on the local server. If you try it how you have it at the moment, you will put every file every time you read a line from you input file, so one file will be put once (no worries there), but two will be put twice (hmmmm) or 10 files will be put ten times EACH. if the files are big then you could be thrashing things about repetitively quite a bit. Do you really want to only put files with a dot in their name? From unix, an "mput *" is all that is required to state all files, but you are also sending every file with the mput so you may duplicate the FTP later on if you run the job again. Capture the output from the FTP command and look for the success message in your script. The FTP command may still exit with return code zero (i.e. no error) even if the file fails to be written, because the error is remote and the FTP command itself works. If you schedule this with SFTP, then you would get a non-zero return code to test, but it depends on you having the SFTP client & server tools installed. Something like this perhaps:- Code:
while read filename
do
ftp -i -n << EOF > ftp_log.txt
open 192.168.1.75
user loguser PASSWORD
prompt
cd \logs_finacle
put ${filename}
EOF
if [ `grep -c "^226 " ftp_log.txt` -eq 1 ]
then
rm ${filename}
else
echo "Failed to deliver file ${filename}"
exit 99
fi
done < /usr/ftprm.txtBe careful to ensure that the EOF line is only indented with tab characters. Using a space will mean that the block of text passed to the FTP command will be incomplete and the FTP will fail with a strange message. You will need to run an FTP manually to check what the success message you should get is. Mine is prefixed with the line starting "226", so that's what I've used. The ^ states that this is the beginning of the line. I hope that this is helpful. It is a lot to take in at once, so ask if you need some clarification - or should if I've made an error. I would never profess to be perfect! Robin Liverpool/Blackburn UK |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks robin. Its more than my limit. I try to read more on your explanation. am getting an syntax error on the line 3. Code:
ftp -i -n << EOF > ftp_log.txt error: ./ftprm.sh: 0403-057 Syntax error at line 3 : `<' is not matched. Last edited by Scott; 01-07-2013 at 10:52 AM.. Reason: Code tags |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
It is difficult to tell what exactly is the error without seeing your code. By the way I see you are using a while loop to read file-name and opening FTP connection for each file. I suggest using an awk code to get all the file transferred in single connection:- Code:
awk 'BEGIN {
print "ftp -i -n << EOF"
print "open 192.168.1.75"
print "user loguser PASSWORD"
print "prompt"
print "cd \logs_finacle"
} {
print "put "$0
}
END {
print "EOF"
}' /usr/ftprm.txt > ftp_batch
chmod +x ftp_batch
./ftp_batch |
| The Following User Says Thank You to Yoda For This Useful Post: | ||
PikK45 (01-07-2013) | ||
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
I think that the line:- Code:
ftp -i -n << EOF > ftp_log.txt ...should actually be:- Code:
ftp -i -n <<-EOF > ftp_log.txt See if that helps. Sorry about that. Robin |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Copy files listed in text file to new directory | IAmTheGrass | Shell Programming and Scripting | 2 | 11-29-2012 08:57 AM |
| Finding consecutive numbers in version names on a txt file | fox1212 | Shell Programming and Scripting | 10 | 03-17-2011 08:00 PM |
| recursive delete files from txt file or? | plener | UNIX for Dummies Questions & Answers | 4 | 01-31-2011 07:57 AM |
| [Urgent]how to print the file names into a txt file??? | kumarsaravana_s | Shell Programming and Scripting | 15 | 03-12-2007 03:32 AM |
| How can I delete files using a file that containt path and names? | AlvaroD | UNIX for Dummies Questions & Answers | 2 | 09-25-2001 12:51 PM |
|
|