Search code examples
linuxshell

Need to grep two different output but filenames are same


Shell script 1 Test1=command 2>output.txt

Shell script 2 Test1=command 2>output.txt

Shell script 3 and so on

All the shell script will run parallel but how do i differentiate the output.txt file even though I append the filename with dates and seconds output.txt_ddmmyyyyhh:mm:ss all the files will be created same name with date and seconds because it will run at same time and seconds.

Also I need to grep the keyword 'missing pattern' in output.txt file it may exist in either shell script 1 or 2 or 3 output so I want to differentiate filename then only i can able to check the keyword is present or not.

Could you please suggest.


Solution

  • How about using the process-id?

    OUTPUT_FILE_NAME="output-$(date +%C%y%m%d%H%M%s)-$$.txt"
    comannd 2>"${OUTPUT_FILE_NAME}"
    grep "stuff to look for" "${OUTPUT_FILE_NAME}"