使用netcat和grep有条件地运行命令 [英] run a command conditionally with netcat and grep

查看:253
本文介绍了使用netcat和grep有条件地运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要netcat监听HTTP请求,并根据请求,我需要运行脚本。

I need netcat to listen on incomming HTTP requests, and depending on the request, I need to run a script.

到目前为止,我拥有这个;

So far I have this;

netcat -lk 12345 | grep "Keep-Alive"

因此,每次netcat收到一个包含keep-alive ,我需要发布剧本。

So every time netcat recieves a package that contains a "keep-alive", I need to fire a script.

它需要运行在crontab中...

It needs to run in the crontab...

感谢您的帮助!

推荐答案

这个如何?

How about this?

    #!/bin/bash

    netcat -lk -p 12345 | while read line
    do
        match=$(echo $line | grep -c 'Keep-Alive')
        if [ $match -eq 1 ]; then
            echo "Here run whatever you want..."
        fi
    done

将echo命令替换为您要执行的脚本。

Replace the "echo" command with the script you want to execute.

这篇关于使用netcat和grep有条件地运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆