在特定时间间隔之后将控制c发送到linux命令?

时间:2016-02-22 16:33:02

标签: linux shell

Shell Scripting:

我正在对我的路由器进行一些测试,我正在使用mdk3和reaver实用程序。

这是两个命令:

[cmd1]  echo y|reaver -i wlan2mon -b 00:FF:EE:CC:DS:B6 -vv    -l 230
[cmd2]  sudo mdk3 wlan2mon a -a 00:FF:EE:CC:DS:B6

目标:

我正在尝试创建一个将运行[cmd1] 2分钟的shell脚本,然后它会将ctrl + c信号发送到[cmd1],以便它将保存reaver会话。

然后cmd2将运行2分钟,之后也会停止。

这两个将在循环中。

下面是我写的示例脚本,你可以为它添加计时器吗?

    #!/bin/bash

while :; do echo
echo "running mdk for 2 minutes";
timeout 120 sudo mdk3 wlan2mon a -a 00:FF:EE:CC:DS:B6;

echo "mdk finished";
echo "starting reaver for 2 minutes ";

#here timeout won't work, as ctrl+c can only save the state.

//add code here to run reaver utility for two minutes and send ctrl+c to it
echo y|reaver -i wlan2mon -b 00:FF:EE:CC:DS:B6 -vv;
 echo "reaver ran for two minutes";



done  

1 个答案:

答案 0 :(得分:4)

我不熟悉reaver程序,但我认为以下内容应该有效,

# Run reaver as a background process (add &)
echo y|reaver -i wlan2mon -b 00:FF:EE:CC:DS:B6 -vv &
# Save the process id.
reaverpid=$!
# Sleep 2 minutes
sleep 120
# Send SIGINT, which is what ctrl-c normally does.
kill -SIGINT $reaverpid