Re: [netsaint] System time problem with NetSaint
"Roger Flemming/SYD/CEtv" <[email protected]>
| Newsgroups | gmane.network.netsaint.user |
|---|---|
| Message-ID | <[email protected]> |
Hello Amol, I am sure many people will answer your question but I haven't seen any yet, so here goes. Also I hope the list doesn't mind that this post is basically all Perl, very little Netsaint! > Dear Sir, > Thx for the solution! > But im unable to decipher the command here.. > perl -i.bak -pe 's#^\[(\d+)\]#$1 - Your_Time_Correction(eg 2*3600)#e' netsaint.log It's a Perl one-liner script. -i.bak says edit in place, backing up the original with extension .bak. -e says the first argument is the actual script to execute, instead of the script's name. -p says take in a file (the second argument) line by line, putting each line into the default argument $_, execute the script, and printout $_. Thus the file (in this case netsaint.log) will have each line transformed by the contents of that script, with the original saved as netsaint.log.bak. The script itself use the pattern-match-and-substitute operator s/// to search for the start of a line (^) immediately followed by a literal left bracket (\[) followed by one or more digits (\d+) and a right bracket (\]). This is then replaced by $1 - Your_Time_Correction(eg 2*3600), where $1 is anything matched inside the parenthesis earlier (i.e. the digits) and the rest was meant to be replaced by you with your actual correction factor. That is, if the error was 2 hours 3 seconds, you'd actually put #$1 - 7203#. The 'e' right at the end says the replacement string is to be evaluated as an expression, i.e. replace the matched pattern with the digits minus the correction factor. Note there may be a small error here: while the date gets corrected, the square brackets will vanish. It might be better to put perl -i.bak -pe 's#^\[(\d+)\]#"[".($1 - 7200)."]"#e' netsaint.log which should keep the square brackets > is it necessary that it has to be in multiples of 3600 (1 hr) No. The time argument is simply seconds. By 'eg 2*3600' he meant put 7200 if you want 2 hours. > also pls tell me where this command has to be executed. If Perl has been set up correctly on your system you should be able to execute it from anywhere. Note that if you are not in the directory where netsaint.log lives, you will need to give its full path. > Also, I was unable to find any relations between the 10 digit time stamps (eg. 10288....), and the corresponding time value. Please help me to know the logic behind the generation of these time stamps. I dont find any common link between the sequence of the time stamps. Is it using some knind of algorithm? These time stamps are a standard Unix internal way of representing time, commonly known as t_time or epoch time. They represent the number of non-leap seconds past midnight, 1st January 1970, UTC (usually as a signed 32 bit integer) which is roughly how old Unix is. Yes this does mean you will need to get a 64 bit machine before the 2038 crisis! This date format has many advantages: - it is constant through out the world, i.e. time zone independent; - it is very compact (one 32 bit int for seconds, minutes, hours, days, months, and years); - apart from the word size problem in 2038, it runs forever into the past and future without any funny glitches or historical weirdness; - it is very easy to do arithmetic in it, while most other formats are horribly confusing; and - it is very portable. On the down side, it is hard for humans to read, but while we're talking Perl, you can convert epoch dates to human readable format in your own timezone, with: perl -e 'print scalar localtime 1029132827' (Substituting the number in question for the one I entered.) Similarly if you want the current epoch date just go: perl -e 'print time' [...] Stanley wrote: > perl -i.bak -pe 's#^\[(\d+)\]#$1 - Your_Time_Correction(eg 2*3600)#e' netsaint.log > > may be something like what you want, provided you know that the log > entries are __all__ are out by the same constant amount.[...] Or if there is a time before/after which they are bad by a constant amount, you could try something like: perl -i.bak -pe 's#^\[(\d+)\]#$1<1028132827 ? $1 - 7200 : $1#e' netsaint.log Substituting the epoch date where it all went wrong for 1028132827 and the actual error for 7200. May still be some hand editing at the cross-over point if the bad dates went forward in time, though. Cheers, Roger *************************************************************************************************************************************************************************** This email and any files transmitted with it, are confidential and is intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, please notify the system manager. This footnote also confirms that this email message has been scanned by AUSTAR Communications content and virus scanning applications for the presence of computer viruses. ***************************************************************************************************************************************************************************