Dears,
Need help to implement below requirement
A file (detail.txt)contain :
1st column: Stream
2nd column: PathAddress
3rd column: Counterlimit
4th column: TransactionDateColumn
5th column: DateType
6th column: SleepValue
7th column: Status
Need to write a script where it read each line of the file.
Check the status column (0 Not active, 1 active)
then pass as following column values as an argument.
stream
pathaddress
counterlimit on below script.
#!/bin/sh
DATE=`date +"%Y-%m-%d %H:%M:%S"`
LATENCY ()
{
stream=
path=
counter=0
while [ $counter -le $counterlimit ]
do
for files in `ls $path | grep -v .temp | head -3`
do
if [[ -f $files ]] && [[ -s $files ]];
then
if ## 4th column of the detail.txt having value 1
then
TT_FIRST=`awk -F ',' 'NR==1{print $1}' $files`
TT_LAST=`awk -F ',' 'END{print $1}' $files`
FILENAME=`ls $files | cut -d '/' -f6`
TIMESTAMP=$( date -r $files +'%s')
FILE_CR_TIME=$( date +'%Y-%m-%d %H:%M:%S' -r $files)
TRANS_TIME_FIRST=$(date -d @$(printf '%.0f\n' $TT_FIRST) +'%s')
TRANS_TIME_LAST=$(date -d @$(printf '%.0f\n' $TT_LAST) +'%s')
RECORD_TIME_FIRST=$(date -d @$(printf '%.0f\n' $TT_FIRST) +"%Y-%m-%d %H:%M:%S")
RECORD_TIME_LAST=$(date -d @$(printf '%.0f\n' $TT_LAST) +"%Y-%m-%d %H:%M:%S")
TIME_LAG_FIRST=$(expr $TIMESTAMP - $TRANS_TIME_FIRST)
TIME_LAG_LAST=$(expr $TIMESTAMP - $TRANS_TIME_LAST)
DELAY_PROCESS=$((`expr $(date -u +"%s") - $TIMESTAMP`))
TRANS_DIFFTIME=$(expr $TRANS_TIME_LAST - $TRANS_TIME_FIRST)
counter=$counterlimit
else
if ## 4th column of the detail.txt having value 4
then
TTHEX_FIRST=`awk -F ',' 'NR==1{print $4}' $files`
TTHEX_LAST=`awk -F ',' 'END{print $4}' $files`
TIMESTAMP=$( date -r $files +'%s')
FILENAME=`ls $files | cut -d '/' -f5`
FILE_CR_TIME=$( date +'%Y-%m-%d %H:%M:%S' -r $files)
TRANS_TIME_FIRST=$(date -d @$(expr `printf "%d" 0x$TTHEX_FIRST` / 1000) +'%s')
TRANS_TIME_LAST=$(date -d @$(expr `printf "%d" 0x$TTHEX_LAST` / 1000) +'%s')
RECORD_TIME_FIRST=$(date -d @$(expr `printf "%d" 0x$TTHEX_FIRST` / 1000) +"%Y-%m-%d %H:%M:%S")
RECORD_TIME_LAST=$(date -d @$(expr `printf "%d" 0x$TTHEX_FIRST` / 1000) +"%Y-%m-%d %H:%M:%S")
TIME_LAG_FIRST=$(expr $TIMESTAMP - $TRANS_TIME_FIRST)
TIME_LAG_LAST=$(expr $TIMESTAMP - $TRANS_TIME_LAST)
DELAY_PROCESS=$((`expr $(date -u +"%s") - $TIMESTAMP`))
TRANS_DIFFTIME=$(expr $TRANS_TIME_LAST - $TRANS_TIME_FIRST)
counter=100
else
echo "file doesn't exist" >/dev/null
fi
fi
if [ "${FILENAME}" != "" ];
then
echo "${DATE} ${stream} ${FILENAME} ${FILE_CR_TIME} ${RECORD_TIME_FIRST} ${TIME_LAG_FIRST} ${RECORD_TIME_LAST} ${TIME_LAG_LAST} ${DELAY_PROCESS} ${TRANS_DIFFTIME}" | hdfs dfs -appendToFile - /AUDIT/FINAL.csv
else
echo "Filename is empty" >/dev/null
fi
done
((counter++))
sleep $sleepValue
done
}
detail.txt contains:
S1 /streamslz/LZ/S1 100 1 1 10 1
IUCS /streamslz/LZ/AnritsuIUCS 100 4 2 5 1
IUPS /streamslz/LZ/IUPS 100 1 1 5 1
Regards,
sadique