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.
My requirement is I have to read the filename, based on which the files are to be moved to different folders from where to different ftp sites.
Eg. NNABRSTXYZ.txt
where NN is a 2 digit number
AB is a fixed code
RST is folder(s) in working one (also ftp site)
and XYZ is folder(s) inside RST (also folder in ftp site)
Now the script has to read the filename and copy the file to respective XYZ folder(s) in respective RST folder(s) from which the files are to be put into XYZ folder of RST ftp site. This should happen only once for each file and be logged with time of action.
Hope my query is understandable. I regret my English but need help. Someone please help me. Thank you all in advance.
By script, if you mean shell script, then you probably want to look at parameter expansion to extract the pieces of the file name into variables which can in turn be used for the upload. Perl might be another option, too, if something more flexible and powerful than shell scripting is needed.
Also, I would highly recommend reconsidering the use of FTP. You can use SFTP with keys instead. With FTP, there is no way to secure it and your machine will eventually get broken into if you use it on a publicly facing machine. In contrast, SFTP works over SSH which has the most strongly vetted encryption available.
Yes I meant to shell script in Linux. Eventually I will be considering SFTP when things are ready working.
To further my question, there are around 50 RST folders and 10 XYZ folders in it. Also it would appreciable if the script triggers whenever any new files are created (not while being created).
Or you might move to SFTP now, while things are still working It'll be cheaper to do it the right way the first time rather than messing with FTP and then redoing the script(s) for SFTP. Add to that the cost of needing to wipe the hardware and do a clean re-installation after an FTP-related break-in and SFTP is the clear choice.
However, regardless of that, once you have the script ready, you can use inotify to trigger using incron whenever a file is added to a specific directory.
The first step is to have the script. What do you have so far?
I still don't have any script ready yet. That is where I need you guys' help.
Build the script one small step at a time. What do you have for a start, even if is a small start? How much of the parameter expansion makes sense via the link above or any tutorials online?
The style here is to help people over the bumps rather than write scripts out of whole cloth.
This is the script I did so for. Hope this will copy the files into folders or sub-folders as I need.
Can you please check and correct me? Next I need to copy only once. Then have to avoid copying when the file is being written or moved or copied into the watch folder. After that from the destination folders upload to FTP.
You do not need the ; at the end of your cp commands.
Use should use the absolute path in the cd command.
The destination directories are all subdirectories of the files directory?
Have you tested the script to see if it works?
I will rectify and remove the ";" (semicolon) at the end of "cp" commands.
Will rectify and use absolute path also.
Yes the destination directories of "files" directory.
I had tested and it is working.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.