I'm trying to compare the date input from lines of a log file with date of yesterday and if the difference is more than one day, then it prints that line from the log file.
Log file:
$more ActiveX2Alarms.log 2016-09-30 01:40:14 MET;faultManager:network@ET_AO_L_0165_abcde@eNBEquip@eNBInst@x2Grp-0@x2Access-0_424_02_ET_AO_L_0165_abcde_44159@x2Transp-0|alarm-2632-3-698;ET_AO_L_0165_abcde;major;2632 ;lte.IK4009022;3;698 2016-11-01 08:10:51 MET;faultManager:network@ER_AO_L_4283_abcde@eNBEquip@eNBInst@x2Grp-0@x2Access-0_424_02_ER_AO_L_4283_abcde_14179@x2Transp-0|alarm-2632-3-698;ER_AO_L_4283_abcde;minor;2632;lte.IK4009022;3;698 2017-01-03 12:14:31 MET;faultManager:network@EM_AO_L_4065_abcde@eNBEquip@eNBInst@x2Grp-0@x2Access-0_424_02_EM_AO_L_4065_abcde_44094@x2Transp-0|alarm-2632-3-698;EM_AO_L_4065_ abcde;minor;2632;lte.IK4009022;3;698 I have created test environment on Windows using cygwin. In Cygwin, i have successful o/p.
Here is the initial code i used:
awk -v d="$(date -d "yesterday" +'%Y-%m-%d %H:%M:%S')" '$1 " " $2 < d' /cygdrive/f/Script_X2/Final/Last_Trial/ActiveX2Alarms.log Result:
2016-09-30 01:40:14 MET;faultManager:network@ET_AO_L_0165_abcde@eNBEquip@eNBInst@x2Grp-0@x2Access-0_424_02_ET_AO_L_0165_abcde_44159@x2Transp-0|alarm-2632-3-698;ET_AO_L_0165_abcde;major;2632 ;lte.IK4009022;3;698 2016-11-01 08:10:51 MET;faultManager:network@ER_AO_L_4283_abcde@eNBEquip@eNBInst@x2Grp-0@x2Access-0_424_02_ER_AO_L_4283_abcde_14179@x2Transp-0|alarm-2632-3-698;ER_AO_L_4283_abcde;minor;2632;lte.IK4009022;3;698 However when using same command on the main server i received an error:
date: illegal option --d Searching for the error i understood it is related to the installed Solaris packages
$uname -a SunOS xxxxxx 5.10 Generic_150400-15 sun4u sparc SUNW,SPARC-Enterprise $date --version date: illegal option -- version usage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff] $date --help date: illegal option -- help usage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff] So i used following code to avoid this issue, however it is not giving any output...so something is still wrong, please help!
$awk -v YESTERDAY="`TZ=GMT+20 date +'%d-%m-%Y %H:%M:%S'`" '$1 " " $2 < YESTERDAY' ActiveX2Alarms.log awk: syntax error near line 1 awk: bailing out near line 1 $/usr/xpg4/bin/awk -v YESTERDAY="`TZ=GMT+20 date +'%d-%m-%Y %H:%M:%S'`" '$1 " " $2 < YESTERDAY' ActiveX2Alarms.log $ To confirm YESTERDAY variable assignment is successful:
$YESTERDAY="`TZ=GMT+20 date +'%d-%m-%Y %H:%M:%S'`"; echo $YESTERDAY 02-01-2017 16:51:26
awk: syntax error near line 1; awk: bailing out near line 1means you are calling old, broken awk (/usr/bin/awk on Solaris). Never use that awk. On Solaris use /usr/xpg4/bin/awk instead as in your second example or even better install GNU awk (which is what you are using on cygwin) which has its own builtin time functions and then you wouldn't need to mess around withdate.-doption. That means using thegdatecommand instead ofdatecommand. If you are on earlier Solaris then you'll need to actively install GNU coreutils package (includes GNU date).