Home > front end >  Make a datetime variable static
Make a datetime variable static

Time:10-05

I have a script which calls another script in a loop. Below is a sample/draft script.

test3.sh

for i in "${array[@]}";do
sh test4.sh
done

In test4.sh script something like below is happening:

  LogFileDateFormat=%Y%m%d_%H%M%S
    GetDateTime=`date  $LogFileDateFormat`
    LogDirectory="/cred/logs"
    LOG_FILE=$LogDirectory/test4_$GetDateTime.log
.
.Do Something >> $LOG_FILE
.

Now every time the loop is called from test3.sh , a new log is getting created because the log name is appended by date and time. I want to write logs to just a single file.

I thought of some counter mechanism but again I am not able to restrict the LOG_FILE to just one name.

CodePudding user response:

Do the logging inside test3.sh:

logfile=...... 
for  i in "${array[@]}";do
  sh test4.sh >>$logfile
done
  • Related