-1

i have a FTP in a LAN that all day users upload content. This gets bulky and messy due to the large amount of files. Every day i create a new folder with the date and then move all the files from this day, so it can be categorised based on date. i would like to automate it and make a script to run every night at 12:01

  • create a folder with the previous date
  • move all files from the particular day to tha folder

up to now i have found but i do not know how to create the folder based on date and then move all this files to that particular folder. some help please?

  • What FTP server are you using, and what Unix? – Kusalananda Jun 14 '18 at 10:28
0

You can write a bash script and add it to daily crontab.

YOUR_DIR=/your/dir   #All of files in here
YOUR_DEST_DIR=/your/dest   #
YESTERDAY=`date +"%F" -d '1 days ago'`
mkdir -p $YOUR_DEST_DIR/$YESTERDAY 
mv $YOUR_DIR/* $YOUR_DEST_DIR/$YESTERDAY # move all files in your dir to dest folder with "based on previous date"

Add it to your crontab with every night ad 00:01

1 0 * * *

  • It is not clear from the question whether the user has access to GNU date, and it's not clear from your answer what the current directory is supposed to be (where * is expanded). – Kusalananda Jun 14 '18 at 10:19
  • What would happen with files that are in the process of being transferred (especially if $YOUR_DIR is on another filesystem)? – Kusalananda Jun 14 '18 at 10:28
  • the solution is for 2 different setups. One setup has a Debian 9 and the other Ubuntu 16. Both run proftp software. Both are getting correct date and time from ntp. The working directory is in /home/userA/ftp/ and the script will be run as root. – john Jun 15 '18 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.