Visit Our UNIX and Linux User Community


Where is my mystake?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Where is my mystake?
# 1  
Old 10-08-2002
Power 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"

Smilie Smilie

Last edited by Yaki; 10-08-2002 at 11:49 AM..
# 2  
Old 10-08-2002
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.
# 3  
Old 10-08-2002
OK Thanx

Thank You very Much
Smilie Smilie Smilie
# 4  
Old 10-08-2002
Computer Yeah Yeah Yeah I DID IT

Smilie Smilie Smilie Smilie
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
# 5  
Old 10-08-2002
You might want to try something like:
Code:
#!/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.
# 6  
Old 10-08-2002
OK

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!!Smilie Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #165
Difficulty: Easy
Tanenbaum originally developed MINIX for compatibility with Apple Computers.
True or False?

Featured Tech Videos