所以我在bash终端中创建了这个ping扫描,但是我想为此制作一个整洁的脚本文件:
for IPs in 192.168.0.{1..254}; do ping -c1 -W1 $IPs; done | grep -B1 "1 received" | grep "192.168.0" | cut -d " " -f2 > BashPingSweep.txt
我认为我的for循环正确,但我不能将for循环传入其他greps并剪切然后输出。这就是我现在所拥有的:
#!/bin/bash
for IPs in 192.168.0.{1..254}
do
ping -c1 -W1 $IPs
done
grep -B1 "1 received"
grep "192.168.0"
cut -d " " -f2
> BashPingSweep.txt
答案 0 :(得分:-2)
你需要在for循环中管道
for IPs in 192.168.0.{1..254};
do
ping -c1 -W1 $IPs | grep -B1 "1 .* received" | grep "192.168.0" | cut -d " " -f2 > BashPingSweep.txt
done