Как создать sed-скрипт для замены кавычек в файле?

Примерно так:

#!/bin/bash
# I assume "logfile" is the log file. If you just want the last run 
# in the log fil, use date> logfile.
# It is always a good idea to get a time stamp in this kind of logs.
date >> logfile 

# The read takes the input from servers.txt, which is done at the
# bottom using `done < servers.txt`.
# Some people like to do `cat servers.txt | while read -r hostname ; do`
# but they get negative comments on stackexchange :-)
while read -r hostname ; do

    # Test if the host is up with a simple ping
    # Throw away all output.
    if ping -c1 "$hostname"  > /dev/null 2>/dev/null; then

        # We now test if a host is up with a simple command, echo.
        # with -o PasswordAuthentication=no, we make sure that password
        # authentication is not used. Output the result to the logfile.
        if ssh  -o PasswordAuthentication=no "$hostname" echo ' '; then
            echo "OK - $hostname" >>logfile
        else
            echo "AArrrghhh $hostname" >> logfile
        fi
    else
        # I assumed you want some idea of how many servers are skipped.
        echo "skipped $hostname" >> logfile
    fi
done < servers.txt

Это быстрая запись, и, вероятно, потребуется некоторая настройка. Комментарии должны дать вам несколько советов о том, что проверить.

1
29.07.2021, 22:36
0 ответов

Теги

Похожие вопросы