我需要从 bash 脚本刷新 memcached 实例,我发现以下命令可以执行该作业:
echo 'flush_all' | ncat localhost 11211
但我的问题是脚本没有继续执行下一个命令,而是以ncat
的响应停止:
如果我在控制台上手动发送命令,我需要执行一个操作CTRL+C
来终止该进程。
echo
我认为这是命令的正常行为ncat
,但我不知道如何绕过它...你知道如何解决它吗?
答案1
您是否尝试过使用 的一些计时选项ncat
?以下是 的相关事件摘录man ncat(1)
。
时间选项
These options accept a time parameter. This is specified in seconds by default, though you can append ms, s, m, or h to the value to specify milliseconds, seconds, minutes, or hours. -d time, --delay time (Specify line delay) . Set the delay interval for lines sent. This effectively limits the number of lines that Ncat will send in the specified period. This may be useful for low-bandwidth sites, or have other uses such as coping with annoying iptables --limit options. -i time, --idle-timeout time (Specify idle timeout) . Set a fixed timeout for idle connections. If the idle timeout is reached, the connection is terminated. -w time, --wait time (Specify connect timeout) . Set a fixed timeout for connection attempts.
因此,在您的情况下,您应该运行echo 'flush_all' | ncat -i 10s localhost 11211
。