Where is my mystake?

#!/bin/bash
while [true]
do
who > .f
who > .s
diff .f .s > .t
if [ -s .t ]
then
echo "In System Stranger"
break
else
continue
fi
done

It doesn't work,when I connect to localhost with SSH
and It doesn't do echo "In System stranger"

:frowning: :frowning:

You would need to login after the "who > .f" finishes and before the "who > .s" starts for this script to behave the way you want. That is a very short period of time. Putting a lengthy sleep between them will increase the chance that it can catch some logins, but you will not catch them all with this technique.

You need to rewrite the script to eliminate the race condition.

Thank You very Much
:slight_smile: :slight_smile: :slight_smile:

:smiley: :smiley: :smiley: :smiley:
yeah I DID IT
It's work
try it yourself

#!/bin/bash
who > .s
while [true]
do
who > .f
diff .f .s > .t1
if [-s .t1 ]
then
echo "In System stranger"
break
else
continue
fi
who > .s
diff .f .s > .t
if [ -s .t ]
then
echo "In System Stranger"
break
else
continue
fi
done

You might want to try something like:

#!/bin/bash 
who > .s
while true ; do
         sleep 5
         who > .f
         diff .f .s > .t1
         if [-s .t1 ] ; then
              echo "In System stranger"
              mv .f .s
         fi
done

The sleep is just to reduce the load that the script will put on the system.

OK,
But My version is work too!!!

Sorry for my Bad English I'm from Armenia.
And I'm 14.
Well Thanx
I think it doesn't need to continue discuss or....
thanks to Perderabo!!:slight_smile: :slight_smile: