0
我想写一个bash脚本,将采取谁的输出,解析它与awk拉IP地址,然后检查它与IP地址阵列......听起来很简单,但他们脚本我放在一起似乎没有工作,我已经在OSX和Ubuntu上测试它,任何人都可以找到原因吗? !检查IP阵列与Bash
ip_address_is_safe() {
local address_to_test=$1;
for safe_ip in "${safe_ips[@]}"
do
if [[ $safe_ip == $address_to_test ]];
then
return 0;
fi
done;
return 1;
}
who="root pts/0 2011-10-03 23:13 (99.99.999.999)
root pts/0 2011-10-03 23:13 (12.12.121.121)
root pts/0 2011-10-03 23:13 (14.14.141.141)
root pts/0 2011-10-03 23:13 (127.0.0.1)
";
safe_ips=("(14.14.141.141)" "(127.0.0.1)")
old_ifs=$IFS;
export IFS="
";
for word in $who; do
remote_connected_ip=`echo $word | awk '/(23)/ {print $5}'`;
if (ip_address_is_safe "$remote_connected_ip")
then
echo "ip was ok - $remote_connected_ip"
else
echo "ip was not ok - $remote_connected_ip"
fi
done;
它使报告每个IP为 “知识产权是不正常”
干杯3
注意到和固定的错字 – RailsSon