LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-05-2007, 02:06 AM   #1
linuxmaveric
Member
 
Registered: Aug 2007
Location: Southern California
Distribution: Ubuntu 8.04 for my desktop & FreeBSD 7.0 for my server blade.
Posts: 31

Rep: Reputation: 15
Cool Need help writing a simple bash script


I am new to linux and I have a question?

How can I write a simple bash script that determines the number of pseudoterminals being used on a system? Can someone help me out with a sample code?
Thanks for your time.

RR.

Last edited by linuxmaveric; 12-06-2007 at 06:54 PM.
 
Old 12-05-2007, 02:22 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by linuxmaveric View Post
I am new to linux and I have a question?

How can I write a simple bash script that determines the number of pty's being used on a system? Can someone help me out with a sample code?
Thanks for your time.

RR.
check the output of who -a command. that's one way
 
Old 12-05-2007, 07:28 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
My system has tty and pts, but no pty

You will probably get better information if you tell us what you are trying to do---eg do you want to know who is logged in?
 
Old 12-06-2007, 06:53 PM   #4
linuxmaveric
Member
 
Registered: Aug 2007
Location: Southern California
Distribution: Ubuntu 8.04 for my desktop & FreeBSD 7.0 for my server blade.
Posts: 31

Original Poster
Rep: Reputation: 15
Here is the sample code.

I made the original post to get some ideas from anyone out there. Well...no luck! However, I talked to some clever linux aficionados at Orange County Linux Users Group here in Southern California and here is the sample codes:! I tried them all out and they worked like a charm.

One way:
> $ ls /dev/pts/* | wc -l
>
> Another:
> $ finger | grep -wc pts
>
> One more way:
> $ ps faux | tr -s ' ' '\t' | cut -f 7 | grep -w pts | sort | uniq |
wc -l
>
Wow, that's a lot of methods!

I think the most elegant one was `w -h | wc -l`

I figured out yet another one:
who -q | grep \#

If you want only the number:
who -q | grep \# | sed 's/.*=//'

or:
u=`who -q | grep \#`; echo ${u/*=/}


_______________________________________________
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash (help writing script) lebabyg Linux - General 7 07-04-2006 05:22 PM
Help writing a simple script Garibaldi3489 Linux - General 10 12-18-2004 06:22 PM
writing a bash script poiuytrewq Linux - Newbie 2 10-07-2004 10:26 PM
Simple script writing help - digital camera EuroJovi Linux - General 2 02-01-2004 04:01 PM
writing bash script ankitgdit Programming 4 08-19-2003 06:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration