Home>

I apologize for being a very rudimentary question.

I want to output the string "C" from the B file in the A directory of each server on Linux.

Background

After running the shell on each server, I want to check if the string "Successfully completed" exists in the work log in order to confirm that the shell completed with the correct operation.

The log of/A/B/LOG/(server name) _YYYYMMDD.log of each server is searched.
(Each server has the same path)

The search string is "Completed successfully."

Error message

On one server

rsh server name cat (server name) _YYYYMMDD.log | grep "Completed successfully."


I would like to batch process what I check with while read line etc.

I don't know what to do after placing a text file with a list of hostnames in the work directory.

echo hostname.txt | while read line
do
  echo "$line"
command
done


I searched, but I was confused and struck in the form shown above.

  • Answer # 1

    It was probably not beautiful but it was solved.
    cat hostname list.txt | awk '{print $2}' | while read line
    do
    rsh $line -n ​​"cat/A/B/C _ $(date +"% Y% m% d ") .log | grep" Completed successfully ""
    ls -l/A/B
    How about using done

  • Answer # 2

    grepand the shell's file glob.
    As an example

    $grep C * _X.log