I am trying to run the following Script on AIX Server. The script checks if first field is EFFECTIVE_TIME , if it is then it converts second field in readable format else it redirects entire line to $MAIL. Both the mentioned files exists prior to running the script
#!/bin/ksh
MAIL=~/backup_scripts/Changed_Policy_Details.txt
TMP=~/backup_scripts/List_of_Changed_Policies_tmp1.txt
while read line
do
read -a arr <<< $line
if [[ ${arr[0]} == EFFECTIVE_TIME ]];then
a=`perl -le "print scalar(localtime(${arr[1]}))"`
echo ${arr[0]} $a >> $MAIL
else
echo $line >> $MAIL
fi
done < $TMP
The $TMP and $MAIL File exists and the contents of $TMP are as follows :
Contents of /usr/openv/hpbackup/db/class/serverfgt/info :
ACTIVE 1
EFFECTIVE_TIME 1279345218
GRANULAR_RESTORE_INFO 0
Contents of /usr/openv/hpbackup/db/class/servertyg/schedule/Full/days :
0 13400 21000
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
Contents of /usr/openv/hpbackup/db/class/serverglt/info :
ACTIVE 0
EFFECTIVE_TIME 1279643561
GRANULAR_RESTORE_INFO 1
I am getting following error from AIX 5.3.
0403-057 Syntax error at line 4 : `<' is not expected
Could someone please help. I am not getting errors on Red Hat Server but problem only on AIX.
According to your script you're interested only in the strings which begin with EFFECTIVE_TIME as the 1st word. In awk we have 2 statements - the first statement is for the strings, which have EFFECTIVE_TIME as the 1st word, and the second statement is for all other strings.
In the second case (easiest case) we just print the string itself. It is usually done with print $0 .
In the first case we have to transform UNIX seconds to "normal" representation of the date. AIX standard awk doesn't have function to work with time/date as GNU awk, but ksh93 has.
So based on the input data we form a new script, which will be executed by ksh and transforms timestamp. If you run the one-line without | ksh93 , you will see the script written with awk. Something like:
I am getting desired Output on AIX 7.1. It seems that the ksh93 version is old on AIX5.3
Also Could you please help in converting epoch timestamp from the below file. The 7th field is epoch timestamp :
78903 0 1 WEEKEND_FULL_ORACLE_BKP Full GYUI-12543 1446541202 0000006420 0000000000 186880
78401 0 1 WEEKLY_FULL_UNIX_BKP Full WEEKLY_TEST 1446508902 0000038818 0000000000 448755456
78306 0 1 WEEKLY_FULL_UNIX_BKP1 Full FTYU-32145 1446455973 0000091647 0000000000 390188288
I am able to convert the 7th field alone but when I am trying to place all the fields in the output report ( 1st to NF fields) then I am getting error. Below command worked