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.
Since creation time of a file is not saved in the inode, you will have to store it somewhere else. One way could be to maintain a list where the directory name and creation timestamp is stored in to keep track of it.
This one you could parse and calculate it's age to decide if it's time to delete it.
If allowed in your environment, you could code the timestamp into the directory name so you would not have to maintain an extra text file.
I don't quite understand your question - specifically the part in red color. My hunch is that you want to email the information in your file. It might be a good idea to give an example of the email you want to send.
Otherwise, maybe you want to do something like this -
(str=""; while read x; do [ "$str" = "" ] && str="$x" || str="$str,$x"; done <input; echo $str) | mailx -s"these are the dir 20 days expired like that" admin@yoursite.com
where "input" is your input file containing all the information.
#!/bin/bash
cut="cut -d"/" -f4 anish"
for i in $"(find /anish -ctime -20 > anish)"
do $cut|mail root@localhost -s "These directories are 20 days old "
done
above script which i wrote for to find the directories are created before 20 days old and that deatails automatically send to admin throug mail. this is right way?? or any other way is available??