We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

script to check if user logged in

script to specify the name of the user to be checked, the frequency in seconds at which the script should check. If a checking frequency is not specified, it should default to 60 seconds
So far I have got

frequency=$0
user=$1
#!/bin/sh
while [ $* -gt 60 ]
do 
who|grep $1 > /dev/null
if [ $? -z 0 ]
then
echo "users $1 is logged"
break;
else 
echo "waiting"
sleep 10
fi
2
Contributors
2
Replies
1 Week
Discussion Span
2 Years Ago
Last Updated
5
Views
Question
Answered
xxyuri
Newbie Poster
3 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

probably something like

#!/bin/sh
if [ $# -eq 0 ]; then
  echo "usage: waiton <user> <frequency>"
  exit 0
fi
user=$1
frequency=$2
if [ -z "${frequency}" ]; then
frequency=60
fi

while $(true); do
  count=$(who | grep ${user} | wc -l)
  if [ ${count} -gt 0 ]; then
    echo "user ${user} is logged on ${count} times"
    exit 0
  fi
  echo "waiting for ${user}"
  sleep ${frequency}
done
chaosless
Newbie Poster
3 posts since Jan 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Thank you,Chaosless ,script working perfecly and very neat

xxyuri
Newbie Poster
3 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 2 Years Ago by chaosless

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0629 seconds using 2.66MB