shell脚本案例学习
循环求 1-100 的每一步和 —案例
j=0
i=1
while((i<=100))
do
j=$((j+i))
echo $j
((i++))
done
每 30 s循环判断一次 user 用户是否登录系统 —案例
设置了一个次数,如果循环了五次在user文件中添加user用户,表示用户登录
USERS="user"
Times=0
while true; do
echo "$Times"
if [[ $Times == 5 ]]; thenuser >> user((Times++))
fiecho "The Time is $(date +%F-%T)"sleep 30NUM=$(grep "$USERS" user| wc -l)if [[ $NUM == 1 ]]; thenecho "The $USERS is login in system."fi
done
没+1,不知道什么原因
检查了以下,逻辑错了,++放在外面,同时重定向也写错了,没加echo
USERS="user"
Times=0
while true; do
echo "$Times"
((Times++))
if [[ $Times == 5 ]]; thenecho user >> user
fiecho "The Time is $(date +%F-%T)"sleep 30NUM=$(grep "$USERS" user| wc -l)if [[ $NUM == 1 ]]; thenecho "The $USERS is login in system."fi
done
这下ok了