UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 6th, 2007, 03:23 AM
livingsword livingsword is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Posts: 12 livingsword User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 6 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old June 6th, 2007, 08:50 AM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
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

Reply With Quote
  #3  
Old June 6th, 2007, 12:11 PM
livingsword livingsword is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Posts: 12 livingsword User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 6 sec
Reputation Power: 0
Thanx im trying hard to improve my skills.

you have been a great help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Checking user login


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT