如何检查用户是否断开连接,是否是新的断开连接以及执行操作的服务器?
How to check if a user disconnected, if it's a new disconnection and the server on which the action was made?
我必须创建一个 shell 程序,这样每次某些用户(作为参数给定)从系统 connect/disconnect 时,如果它是一个新的 connection/disconnection 和执行操作的服务器。有人可以给我一些想法或使用哪些命令。我很难使用命令 'who' 和 'finger'.
自己解决了
#!/bin/bash
function SaveInfo
{
echo "( Last information saved about "$user" )" >> LAB6_Log
echo "The server Time and Date" >> LAB6_Log
echo " " >> LAB6_Log
last | grep $user | awk '{print " "" "" "" "" "" "}' >> LAB6_Log
echo "____________________" >> LAB6_Log
echo " " >> LAB6_Log
}
function CheckUser
{
for user in $( who | awk '{print }' | uniq )
do
if [ $user == "" ]
then
return 0
fi
done
return 1
}
clear
echo "+____________________________________________________________+"
echo " "
if [ $# -eq 0 ]
then
echo "You did not enter a username. Please enter one... or more, I guess."
else
echo "The information about the following users are saved in the file: LAB6_Log "
for i in $@
do
n=0
m=0
echo "Supervising this user: "$i" "
while [ $n -le 4 ]
do
user=$i
CheckUser $user
TheAnswer=$?
if [ $TheAnswer == 0 ]
then
n=$((n+1))
echo "checking again for "$i"..."
sleep 2
else
m=$((m+1))
echo "checking again for "$i"..."
sleep 2
fi
if [ $m == 4 ] && [ $n == 0 ]
then
echo "User not found. Probably not existing"
break
fi
if [ $n == 4 ]
then
echo "Saving information..."
echo "____________________NEW CONNECTION" >> LAB6_Log
SaveInfo $user
echo "Information saved!"
break
fi
if [ $m == 4 ] && [ $n != 0 ]
then
echo "Something happened. User maybe disconnected..."
echo "____________________NEW DISCONNECTION" >> LAB6_Log
SaveInfo $user
echo "Saved last information possible."
break
fi
done
done
echo "Exiting..."
fi
echo " "
echo "+____________________________________________________________+"
我必须创建一个 shell 程序,这样每次某些用户(作为参数给定)从系统 connect/disconnect 时,如果它是一个新的 connection/disconnection 和执行操作的服务器。有人可以给我一些想法或使用哪些命令。我很难使用命令 'who' 和 'finger'.
自己解决了
#!/bin/bash
function SaveInfo
{
echo "( Last information saved about "$user" )" >> LAB6_Log
echo "The server Time and Date" >> LAB6_Log
echo " " >> LAB6_Log
last | grep $user | awk '{print " "" "" "" "" "" "}' >> LAB6_Log
echo "____________________" >> LAB6_Log
echo " " >> LAB6_Log
}
function CheckUser
{
for user in $( who | awk '{print }' | uniq )
do
if [ $user == "" ]
then
return 0
fi
done
return 1
}
clear
echo "+____________________________________________________________+"
echo " "
if [ $# -eq 0 ]
then
echo "You did not enter a username. Please enter one... or more, I guess."
else
echo "The information about the following users are saved in the file: LAB6_Log "
for i in $@
do
n=0
m=0
echo "Supervising this user: "$i" "
while [ $n -le 4 ]
do
user=$i
CheckUser $user
TheAnswer=$?
if [ $TheAnswer == 0 ]
then
n=$((n+1))
echo "checking again for "$i"..."
sleep 2
else
m=$((m+1))
echo "checking again for "$i"..."
sleep 2
fi
if [ $m == 4 ] && [ $n == 0 ]
then
echo "User not found. Probably not existing"
break
fi
if [ $n == 4 ]
then
echo "Saving information..."
echo "____________________NEW CONNECTION" >> LAB6_Log
SaveInfo $user
echo "Information saved!"
break
fi
if [ $m == 4 ] && [ $n != 0 ]
then
echo "Something happened. User maybe disconnected..."
echo "____________________NEW DISCONNECTION" >> LAB6_Log
SaveInfo $user
echo "Saved last information possible."
break
fi
done
done
echo "Exiting..."
fi
echo " "
echo "+____________________________________________________________+"