jeudi 11 janvier 2018

Script Output Overwites the old data instead in output file of write to new line

I have came with script to check Name node status. When i ran manually. The Status of namenode written in a file and when i run again the second attempt output adds a new line in the old file. But I have scheduled in cron to run every 15 Minutes. But the cron job overwrites the old data and i can see only last run status. How can i add new line through cron as well.

!/bin/bash

NOW=$(date +"%m-%d-%Y") fname=active.$NOW.log [ ! -f $fname ] && > /opt/hd/sh/bin/$fname if [[ $(hdfs haadmin -ns ATcluster -getServiceState nn1) = *active* ]]; then echo "date +"%Y-%m-%d %H:%M:%S"active NN1" >> /opt/hd/sh/bin/$fname elif [[ $(hdfs haadmin -ns ATcluster -getServiceState nn2) = *active* ]]; then echo "date +"%Y-%m-%d %H:%M:%S"active NN2" >> /opt/hd/sh/bin/$fname else echo "date +"%Y-%m-%d %H:%M:%S"stopped state" >> /opt/hd/sh/bin/failed.$NOW.log fi

Output

cat active.01-1 cat: active.01-1: No such file or directory [root@hadmat01 bin]# cat active.01-11-2018.log 2018-01-11 06:00:04 active NN1 --> it should write nw output like below through cron job [root@hadmat01 bin]# cat failed.01-11-2018.log 20180111 00:00:05 stopped state 20180111 00:15:05 stopped state 20180111 00:30:05 stopped state 20180111 00:45:05 stopped state

Aucun commentaire:

Enregistrer un commentaire