Calculate Time Period in Scripting


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculate Time Period in Scripting
# 1  
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
# 2  
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.

Date arithmetics are often being discussed about in the forum - try using the search function.
You can also check out this:
https://www.unix.com/answers-frequent...rithmetic.html
# 3  
Hi zaxxon,

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:
drwxr-xr-x 2 root root 4096 Mar 16 18:48 anish
this directory has to be deleted automatically after three months, is it possible with the help of this (Mar 16 18:48) date/time to calculate.


With Regards
Anish Kumar.V

---------- Post updated 03-17-11 at 04:37 PM ---------- Previous update was 03-16-11 at 07:01 PM ----------

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

I separated the directory name which are created before 20 days alone like this,
Quote:
anish
dinesh
linux
now i want to send mail to admin these are the dir 20 days expired like that...how we can do that in scripting please guide me to do....


With Regards
Anish Kumar.V
# 4  
Quote:
Originally Posted by anishkumarv
...now i want to send mail to admin these are the dir 20 days expired like that...how we can do that in scripting please guide me to do....
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 -

Code:
(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.

tyler_durden
# 5  
Hi durden_tyler,

Thanks for your Reply

Code:
#!/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??

With Regards
Anish Kumar.V
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 03-17-2011 at 11:47 AM.. Reason: code tags, please!
# 6  
Quote:
Originally Posted by anishkumarv
...
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??...
You tell me.
Does it work?
If it does, then it is the right way.
If it doesn't, then it is the wrong way.

tyler_durden
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #275
Difficulty: Easy
OpenSolaris is the only version of the System V variant of UNIX available as open source.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate Time diff in milli milliseconds(Time format : HH:MM:SS,NNN)

Hi All, I have one file which contains time for request and response. I want to calculate time difference in milliseconds for each line. This file can contain 10K lines. Sample file with 4 lines. for first line. Request Time: 15:23:45,255 Response Time: 15:23:45,258 Time diff... (6 Replies)
Discussion started by: Raza Ali
6 Replies

2. Shell Programming and Scripting

To get the Files between Time Period

All, How to get the list of files through a unix command which exists / created / updated between 8 PM to 11:59 PM from a particular location. Regards Oracle User (3 Replies)
Discussion started by: Oracle_User
3 Replies

3. Shell Programming and Scripting

Get connection count over a period of time

I used this script to get the connection to a domain in two specific minutes. I need to extend to give result over a range of minutes. The below gives total number of connections in the minutes 00:40 and 01:13 on 22nd March. egrep "22/Mar/2013:00:40|22/Mar/2013:01:13"... (1 Reply)
Discussion started by: anil510
1 Replies

4. HP-UX

memory consumption over a time period

Hi, Can some one please tell me how do I generate a report of the Memory Consumption over a time period: HP-UX B.11.31 U ia64 0440531406 unlimited-user license I normally use glance to monitor memory in run time. Note: I do not have root privileges. Thanks Danish ... (5 Replies)
Discussion started by: danish0909
5 Replies

5. UNIX for Dummies Questions & Answers

Start Time and period of a PID

Hi, Below is my OS details. uname -an SunOS mymachine 5.10 Generic_144488-07 sun4v sparc SUNW,SPARC-Enterprise-T5220 I need to know when was my Apache server last started. Whats is the best and most reliable way to find out not just for Apache but for any PID per say? I am... (16 Replies)
Discussion started by: mohtashims
16 Replies

6. Shell Programming and Scripting

grep /target greater than time period??

Hey guys, I'm fairly new at unix shell scripting and I have a quick question. Quick overview I devolped a script where I generate a file ..and I want to grep any time greater than 30 minutes. What i do is runa command to generates the below and puts it into a file: I run ./ggsci << endit... (4 Replies)
Discussion started by: nomiezvr4
4 Replies

7. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

8. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

9. UNIX for Dummies Questions & Answers

Determining load average over a period of time

How can i determine the load average of a centos server for the last 1 hour? (3 Replies)
Discussion started by: proactiveaditya
3 Replies

10. Shell Programming and Scripting

Run job for a period of time

I have a job that runs for an unspecified amount of time. I want to run this as a cron job for a specified amount of time, say 2 hours. Once the time is up, the program should be killed in the middle of execution. How can I do this? Thanks. (5 Replies)
Discussion started by: cooldude
5 Replies

Featured Tech Videos