Check whether a root file was closed properly (with bash)

Hello,
how I check if a root file was closed properly within a bash script?

thanks,
tb

works with: ErrorStat=$(aliroot -q -b $OutputRootFileOfChild | grep error | wc -l)

any “smarter” idea?

See Corrupted ROOT files without reason ?!

#!/bin/bash
for filename_to_check in *.root
  do
    root.exe -b -l -q -e "auto f = TFile::Open(\"$filename_to_check\"); if (f == nullptr || f->IsZombie()) { cout << \"There is a problem with the file: $filename_to_check\n\"; exit(1); }"
    if [ $? -ne 0 ]; then
        echo $filename_to_check has error
        exit 1
   fi
 done ;

I think the question is not about a completely “broken” / “unusable” files but about files which have not been properly closed so that you can still “use” them (i.e. files for which one gets the “recovered” message).
Probably something like this:

root.exe -b -l -q -e "TFile *f = TFile::Open(\"$filename_to_check\"); if ((!f) || f->IsZombie() || f->TestBit(TFile::kRecovered)) { cout << \"There is a problem with the file: $filename_to_check\n\"; exit(1); }"

@Wile_E_Coyote Yes, I think you are right :slight_smile: