I have a script which has to be scheduled to run 3 times a day.
My script picks the required fields from logfile and stores the data in a.csv file.
Sample data.
my logfile contain:
0097A,0374D,100903,1519,00000606191
0097A,C88RA,100903,0724,00000606105
So the output of first execution will be stored in a.csv file:
0097A,0374D,100903,1519,00000606191
0097A,C88RA,100903,0724,00000606105
Before second execution of script now logfile contain:
0097A,0374D,100903,1519,00000606191
0097A,C88RA,100903,0724,00000606105
0097A,C88RA,100903,0726,00000606106
0100A,0374A,100903,1358,00000355348
0115A,6652A,100903,1103,00000489132
0118A,6652A,100903,1301,00000339704
So my output should be appended to a.csv file keeping old data and appending new data to it with some line and time in between as below:
I want my output like this.
0097A,0374D,100903,1519,00000606191
0097A,C88RA,100903,0724,00000606105
-------------------2nd Phase $time--------------
0097A,C88RA,100903,0726,00000606106
0100A,0374A,100903,1358,00000355348
0115A,6652A,100903,1103,00000489132
0118A,6652A,100903,1301,00000339704
---------- Post updated at 05:55 AM ---------- Previous update was at 05:48 AM ----------
#!/bin/sh
time="`date '+%H%M%S'`"
date=`date +%y%m%d -d"1 day ago"`
inbound_dir=/vist/logfiles/to_solmis
mkdir -p /vist/sumit/in_ASN.$date.$time
cp `grep -il ST~856~ $inbound_dir/*$date*` /vist/sumit/in_ASN.$date.$time/
for i in /vist/sumit/in_ASN.$date.$time/*
do
#cp `echo $i` /vis/sumit/inbound.$date
tr -c '[A-Z] [0-9] [a-z] ~' '[ *]' <$i > b
awk -F "DTM~" '{print $1}' b > c
awk -F "~SH~" '{print $2}' c > d
awk -F "~" '{print $1","$2","$3","$4","$11}' d >> a.csv.$date.$time
done
rm b
rm c
rm d