This method may bring you some trouble if your script is not running, for some reason, the first of the month. Once it comes on 2 or later, he found a dirty environment and will have undefined behavior. It is better to go on an approach that is fully controlled and leaves no uncertainty. In my case, for this kind of scripts, I have the following steps:
Code:
Get the day
Get month
Recover year
# All this can be done by cutting the output of 'date' of a sudden cut or awk.
If the directory does not exist the year
Then Create the directory of the Year
Endif
Go to the directory of the Year
If the directory does not exist in the month
Then create the directory of the month
Endif
Go to the directory of the month
If the directory does not exist the day
Then create the directory of the Day
Endif
Go to the directory of the Day
Copy the desired files
All this is done very easily in bash and a perfectly deterministic behavior. Good luck for coding.
Bookmarks