Linux - NewbieThis 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.
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.
We have multiple Linux base server and each server has common directory structure . i need to copy latest created files to one FTP location . for example .
Server ip - 10.0.3.4
server file detail as below.
-rw-rw-rw- 1 tux tplinux 8194 Oct 11 19:03 WT4755.20151011190001
-rw-rw-rw- 1 tux tplinux 1903 Oct 11 19:15 WT4755.20151011191501
-rw-rw-rw- 1 tux tplinux 932 Oct 12 16:45 WT4755.20151012164501
-rw-rw-rw- 1 tux tplinux 1392 Oct 13 05:30 WT4755.20151013053001
so i only want to copy last file which will be dynamic value and if post that any new file created for same day should be automatically copy to ftp location .
path : /home/tplinux/out/wscale/
FTP location with user name password and insight directory detail as below.
ftp -nvi 10.0.30.100 << EOF
user posftp SAPPOS
cd EODSOD
mput file...
bye
EOF
i have put my effort as per my understanding and wrote script.
but it is not working .
#!/bin/sh
#Script Name : WS update .
# Release Version : 1.1
# Developed By : Application Team - Ahd
# File Will generate : home/tplinux/
I've used lftp and recommend it but haven't done exactly what you describe. At least one suggestion in the above link seems to describe using lftp for similar file synchronization.
P.S. If the user/password in your example script are the real ones I suggest you edit your post to replace them with fake ones. Even though your IP is internal to your network letting bad guys have any real detail is not a good idea.
In addition, the obvious errors are that new1 is not a variable and that mput will transfer the file and not its contents. One way to fix your script would be to use the filename since it contains the date.
Code:
.
.
.
new1=$(date +%Y%m%d )
ftp -nvi 10.0.30.100 << EOF
user posftp SAPPOS
cd EODSOD
mput *$new1*
bye
EOF
mput *$new1* will transfer all files that match *20151013* i.e. WT4755.20151013053001 if running the script today (13 Oct 2015)
Base on above feedback and guideline i am able to execute script but one challange i have multiple files of today's date but it is getting transfer only first files of today's date not all files.
Let me clarify my requirement. at one of the server below list of files
tux@TPL4755 ~/out/wscale (1019) ll
total 12
-rw-rw-rw- 1 tux tplinux 5311 Oct 14 11:30 WT4755.20151014113001
-rw-rw-rw- 1 tux tplinux 35 Oct 14 13:00 WT4755.20151014130001
when above both files are today's date i want to scedule script every 15 min if any new files create it should be append or take all files dump at FTP of today's date .
my updated script .
#!/bin/sh
#Script Name : WS update .
# Release Version : 1.1
# Developed By : Application Team - Ahd
# File Will generate : home/tplinux/
The -i option (i.e. ftp -nvi ...) does the same thing as the prompt command.
In my previous post I gave the OP an alternate solution to copying using file name expansion based up the embedded date in the name instead of using a list created from the output of the ls command. Hence the asterisks.
The string created by the output of the $(ls -lrt | awk '{print $6$7" "$9 }' | grep `date +%b""%d` | awk '{print $2}') still contains the end line characters that separates the file names which causes an error and only transfers the first file.
The command new1=$( date +%Y%m%d ) creates a string with the date and then mput *$new1* will expand to any file name that includes the date.
Just curious, but is rsync not an option?
That would be SO much easier than attempting to sync using ftp!
rsync would indeed be the best solution if the target site allows ssh but from what the OP wrote I assumed the target only allowed him to do ftp logins. rsync won't work for an ftp target which is why I suggested lftp.
Have you researched lftp (mirror or reverse mirror mode?), ftpsync, or other tools that automate this using only FTP access?
FYI: Rsync can run in client/server mode without ssh, rsh, ftp, or any other external tools. This does require that you have permissions to start it properly on BOTH ends, so a 'pure' ftp option might be preferred in this case.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.