#! /bin/bash
while :
do
filenames=$(ls -rt *.log | tail -n 2)
echo $filenames
cat $filenames > jive_log.txt
sleep 0.1
done
I am trying to read latest 2 files from a directory and join them using bash.
However when no files are present in the current directory with an extension .log the command ls -rt *.log fails with error "ls: cannot access *.log: No such file or directory". After the error it looks like the while loop does not execute.
AfterWhat do I do so that the infinite loop continues even if one command fails.
filenames=$(ls -rt *.log 2>/dev/null | tail -n 2)findinstead ofls. 2.) Bash exits only if the errexit optionset -eis used. 3.) Useset -xto debug your script.