Check time and Increase counter


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Check time and Increase counter
# 1  
Old 11-30-2009
Check time and Increase counter

Hi all...

the last two weeks have been very educational... I went through a bunch of websites about linux and its commands.. still not have mastered it nor its many operators ... and symbols. I wish I had more time to dig to the next and unix.com but I m on a deadline for this project.

I have a file with many lines like the following


Code:
 
1259618998,5708852666@ZZZZ.com,txt@YYY.com,0
1259618998,5803013030@ZZZZ.com,txt@YYY.com,0
1259618998,5805300577@ZZZ.com,txt@YYY.com,0

So the pattern is

Code:
 
EPoch_Time,From_Address,To_Address,Count

Well heres what I am told to do...
I
When this script is run it should check each line and compare that line's Epochtime with the current Epcohtime. If 15 mins have passed by then it should increase count value by 1.
II
It should check the count value and if its mod (count/5) is qual to '0'. [ eg if (mod(count/5) == 0) ]
If false increase the count value by 1
If true then I have to send mail to abc.def@xxx.com. Telling which 'from' and 'to' mail address 'combination' is still in the Q.

I have no idea how to use the ^ / $ or any other operator. Any help will be appreciated.
Thanks
# 2  
Old 12-01-2009
For I:
Store the current time in a variable, compare the current time and the time on the file using an if loop, based on the result set the counter value to 1 more.

Please explain the format of the first field of the text assuming it is the time in the input file and the counter operation as there are 2 ways of it working in I & II.
# 3  
Old 12-01-2009
Reply

I dont know how to extract string from the line mentioned. Could you tell me how to do it. so that i could store it in variable eg

VAR1 = Epochtime
VAR2 = Count.

Also i dont know how to replace the count in the line after it had been increased by 1.

The first set of numbers u see is the epoch time of the time that line is created.

I was thinking of running something like

Code:
LC = line Count of file
While ( LC > 1)
      do
       Read  line
           Var1= Epochtime, Var2 = CountValue,
           If [ (CurrentSystemTime - Var1 ) >= 900 ]
                   Var2 = Var2 ++
                   Insert Var2 back into the line replacing the old value
             LC = LC --
           else
             LC = LC --
      done
LC = Line Count of file
While ( LC > 1)
       do
        Read Line
           Var2 = Count value
           If [ mod(var2/5) == 0 ]
               Send line to another file or send email alert to abc.def@xxx.com containg the To and From addess
               LC = LC --
           Else
               LC = LC --
        done

This is a rough idea of how i imagine the logic to be . The pboblem I face is how to extract the values to a variable and how to insert back to the respective line and continue on for each line of the file. This is primitive any optimizing will be helpful.

Epoch time is the representation of time in seconds by the linux system.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if time format is valid

How can I validate if time (HH:MM:SS) argument is valid? I got this from web but I can't modify it to exit the script if the time argument is invalid. echo $1 | awk -F ':' '{ print ($1 <= 23 && $2 <= 59 && $3 <= 59) ? "good" : "bad" }' ex: ./script.ksh 12:34:21 = okay ./script.ksh... (10 Replies)
Discussion started by: erin00
10 Replies

2. Shell Programming and Scripting

IF loop to check the time modified

Hi Frnds, i have a folder test in which files generated daily how to chek the files that are modified on that day as a condition for ex, if then echo "i have got something to do with the file" else echo" sorry" fi i will have more than 3 to 4 files that are modified today. and if... (5 Replies)
Discussion started by: mahesh300182
5 Replies

3. Solaris

Solaris 10- DHCP lease time increase

HI Admins, can anyone tell me how can I increase the lease time in Solaris 10. I want to use that dhcp address for 4 weeks. (2 Replies)
Discussion started by: snchaudhari2
2 Replies

4. Shell Programming and Scripting

Check file time stamp

Hi, I need help to read file in a directory on basis of time stamp. e.g. If file access in last 2 minutes it should not be copy to remote directory. Below is my script. #!/bin/ksh DATE=`date +"%Y-%m-%d_%H%M"` SEPARATER=" " exec < out_interfaces.cfg while read source_path... (10 Replies)
Discussion started by: qamar.alam
10 Replies

5. UNIX for Dummies Questions & Answers

Time check!

How can i do something, that will be doing periodicaly for 24 hours and then do something else. For example: i want to write "time" in a text file every 10 sec but only for the next 24 h and then rewrite all that data to an other file, then again write "time" in the first file every 10 sec,... (5 Replies)
Discussion started by: petel1
5 Replies

6. Shell Programming and Scripting

Check data and time

I am attempting to figure out how to do a time check within my script. For some reason I can not seem to get this to work correctly. I want the script to first see if it is Saturday. If it is Saturday then check to see if it's between the time 5:30am and 6:30am. If it is between 5:30am and... (4 Replies)
Discussion started by: LRoberts
4 Replies

7. Shell Programming and Scripting

Check Time/Date on a server

I have two servers which are not in sync. I need to write a script that checks the time on the corresponding server and another script to call the above script on both the servers simulataneously to check if there is a time difference. Can anyone provide me with such scripts as I am new to... (3 Replies)
Discussion started by: ravneet123
3 Replies

8. UNIX for Advanced & Expert Users

Increase the counter in UNIX

HI! All Iam facing an issue with split comman in unix Prifix=Z_PRICE_NEW`date "+%Y%m%d%H%M%S"` split -5000 Product.txt $Prifix find . -name "$Prifix*" -print | { while read FILE; do mv $FILE $FILE.txt done } when is execute the comman the command is working fine and generating the... (2 Replies)
Discussion started by: mohdtausifsh
2 Replies

9. UNIX for Advanced & Expert Users

increase the logout time

respected sirs, how to increase the logout time in unix...... at present when we r idle for 5 min...... the system is responding with login again.......and the other problem how to add an operator ........plz help to solve my queries thanking u sir ... (1 Reply)
Discussion started by: manikumar
1 Replies
Login or Register to Ask a Question