|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Checking user login
hi, this one those very helpful sites that i have been to.
So im trying to write a bash script which checks if any user has logged-in from more than one terminals, if yes, then display the no. of those logins. So this is how far i have managed to reach, Code:
echo -n "Enter Username : ";
read user;
echo -n "Enter terminal no. : ";
read term;
last $user | awk '{ print $2 }' | grep -c "^pts.$term" >temp
val=`<temp`;
awk '{
if ($val > 1)
printf $user," has logged in terminal pts/",$term," ",$val," times";
}'
i get "unexpected file end" error. Please help. ![]() |
|
#2
|
||||
|
||||
|
There's a couple of problems with your awk command there. awk operates on stdin. i.e. you should either pipe the result of a command to awk/read the input from a file.
The second problem is that you're trying to use a bash variable in your awk script. This can be done but not the way you're trying to do it. In any case, bash should be sufficient for your if/else needs ![]() Code:
1 echo -n "Enter Username : ";
2 read user;
3 echo -n "Enter terminal no. : ";
4 read term;
5
6 val=$(last $user | awk '{ print $2 }' | grep -c "^pts/$term")
7
8 if [ $val -gt 1 ]; then
9 echo ${user} has logged in terminal pts/${term} ${val} times
10 fi
|
|
#3
|
|||
|
|||
|
Thanx
im trying hard to improve my skills.you have been a great help. ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Checking user login |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|