【发布时间】:2015-03-12 18:58:18
【问题描述】:
我的 shell 脚本有问题。它应该读取参数:索引、日期、time1(间隔的开始)、time2(间隔的结束)。 它应该计算用户(索引)在时间间隔 time1-time2 内登录给定日期的次数。 例如:121212 "Jan 14" 00 12
这可行,但我对参数日期有疑问。它不承认这是一个论点。它在 1 月和 14 日将其拆分,这是一个大问题。 我已经在互联网上搜索了几个小时,但我无法在任何地方找到解决方案。 这是我的代码:
#!/bin/bash
read user date time1 time2
list=`last | grep ^$user.*$date | awk '{ print $7 }'`
start=$time1
end=$time2
echo "start $start"
echo "end $end"
count=0
for el in $list ;
do
login=$el
echo "najava $najava"
checkIf(){
current=$login
[[ ($start = $current || $start < $current) && ($current = $end || $current < $end) ]]
}
if checkIf; then
count=`expr $count + 1`
ip=`last | grep ^$user.*$date.*$login | awk '{ print $3 }'`
echo $ip >> address.txt
else
continue
fi
done
echo "The user has logged in $count times in the given time interval"
【问题讨论】:
-
您的脚本似乎没有接受任何参数,那么您在说哪些“参数”?