Search code examples
linuxcommand-linestdoutnfs

Redirecting multiple stdouts to single file


I have a program running on multiple machines with NFS and I'd like to log all their outputs into a single file. Can I just run ./my_program >> filename on every machine or is there an issue with concurrency I should be aware of? Since I'm only appending, I don't think there would be a problem, but I'm just trying to make sure.


Solution

  • That could work, but yes, you will have concurrency issues with it, and the log file will be basically indecipherable.

    What I would recommend is that there be a log file for each machine and then on some periodical basis (say nightly), concatenate the files together with the machine name as the file name:

    for i in "/path/to/logfiles/*"; do
        echo "Machine: $i";
        cat $i;
    done > filename.log
    

    That should give you some ideas, I think.