Original post compared with suggested change from @spacebar:
Quote:
# Original post
while true; do newdate=$(date '+%Y%m%d') ; nowdate=$(date '+%Y%m%d-%H.log'); tail -f /usr/home/ABCD/atimo/log/$newdate/option/OP2/GatewayTransaction.$nowdate ;sleep 5 ; done ;
# Suggested change from @spacebar
while true; do newdate=`date '+%Y%m%d'`; nowdate=`date '+%Y%m%d-%H.log'`; tail -f /usr/home/ABCD/atimo/log/$newdate/option/OP2/GatewayTransaction.$nowdate; sleep 5; done;
The O/P stated that the original problem was "When creating a new file scripts not working".
Both of the above command sequences have this problem (the suggested change just makes an irrelevant change to the date command). They will both go wrong when the application starts a new file because the "tail -f" will lose context.
The big problem is because the script is using "tail -f".
There is no "quick and easy" way round this script design issue except to avoid "tail -f".
My usual approach to log file monitoring is to issue "wc -l" to find out the number of lines in the logfile, record that number in a workfile, then after the time interval calculate the new number of lines, calculate the difference and then issue "tail -n". This is a simplified view because we need to take account of the application starting a new file and will utililise the timestamp on our record file to detect the new file. The simplest approach to the "first time" condition is to do nothing except record the current state. This means that the logfile monitoring script needs to start running exactly one time increment earlier than the first report.
Ps. It always helps to know what Operating System and version you are running and what Shell you prefer.