bash脚本通过curl命令检查网站内容

Ada*_*dam 8 command-line bash scripts webserver curl

我想编写一个脚本来检查网站是否工作正常,通过检查其中的一些内容。如果结果中存在该内容,则打印一条消息告诉网站工作正常,否则将显示错误:

#!/bin/bash

webserv="10.1.1.1" 

Keyword="helloworld" # enter the keyword for test content


if (curl -s "$webserv" | grep "$keyword") 
        # if the keyword is in the conent
        echo " the website is working fine"
else
        echo "Error"
Run Code Online (Sandbox Code Playgroud)

任何建议如何做到这一点?

mur*_*uru 15

你大部分时间都在那里。只需修复您的语法:

if curl -s "$webserv" | grep "$keyword"
then
    # if the keyword is in the conent
    echo " the website is working fine"
else
    echo "Error"
fi
Run Code Online (Sandbox Code Playgroud)

注意thenfi