Calculate Time Period in Scripting
Hi all,
now i am writting one bash script. in that my requirement is i need to create one directory and that the directory details to be stored in one file Ex. date/time and all in one file. after that i need to delete the folder automatically exactly after 3months. between these time period in 2month itself i need to send one mail to admin "regarding this still one month only more to delete the folder" . is it possible to do like that date calculation in script. With Regards Anish Kumar.V Edit/Delete Message |
I haven't used it in a while, but look into logrotate:
http://linux.die.net/man/8/logrotate You don't have to use it for the /var/log tree you can customize your profile to look at other files and delete those after they reach a certain size or age. Takes a bit of fooling with, but I used it to rotate and deprecate logs from an application I wrote so as to not overflow disk size but also keep the logs and offload them once they were swapped out. |
Hi rtmistler,
Thanks for your reply. Code:
mkdir anish | ls -l /root/>> file1 && grep anish file1 using this code i can able to save the directory creation time , like this Quote:
With Regards Anish Kumar.V |
Hi all,
Is it possible using TimeStamp!!! concept |
The find command is very good at finding files and directories of a specified age. I would try to use it as the basis for keeping track of files matching various age thresholds. Keeping track of file and directory age information is redundant, since the filesystem already does this, and is automatically up-to-date.
--- rod. |
Hi theNbomr,
is it possible using "FIND" command to find the age of the directories in a particular path, if more that 2 months of the folder age means its automatically triggered mail to ADMIN, like that..... With Regards Anish Kumar.V |
Something like this, perhaps.
Code:
oldFiles=$(find /some/start/directory -ctime +60) --- rod. |
You can also look at running a script (possibly using find) from within cron, as this (cron scheduling) uses calendar mths.
|
HI chrism01,
Can you post any example, i am quite confused with find command, just now only started to reading the man page of find. With Regards Anish Kumar.V |
Hi all,
using this command i stored the details in one file which are created before 20 days. Code:
find /root/testing/ -ctime -20 > file Then using cut command Code:
cut -d"/" -f4 file Quote:
With Regards Anish Kumar.V |
If you use '-ctime -20' in the argument to find, you will find files that are less than 20 days old (creation time; do you really mean modification time?). From your original post, it sounded like you wanted to find files that are older than a certain age. To do that, you would want to change the leading minus sign in the numeric argument to a plus sign.
Also, the use of cut to trim the leading directory name from files relies on the case that the files found are exactly 4 levels deep from the root. Better would be to use the built-in basename function. Example: Code:
echo $(basename /home/user/directory/file.name) My example showed how to send the list of files to a user by e-mail: Code:
echo $oldFiles | mail -s "Deleting files from /some/start/directory" ADMIN@your.site |
All times are GMT -5. The time now is 04:52 PM. |