LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-27-2013, 03:51 PM   #1
Expedient
LQ Newbie
 
Registered: Jul 2013
Posts: 2

Rep: Reputation: Disabled
How to divide 100 by the amount of logged in users?


I wrote this bash script to call another script written in C that uses threads. My dedicated server can only support 100 threads being used at one time and I am going to be having multiple users on my dedicated server. I am trying to take 100 divided by the number of users logged in to my server so that each will have a fair share of threads. Example: 4 users are logged in to my server at a given time and all 4 are running my script. Each user will have an equal amount of threads that are being used. So 100/4 would be 25 threads per user. All I am trying to do is get 100 divided by the amount of users logged into my server, what would be the best way to do this? I know the 'who' command can tell you how many users are logged in but I don't really know how to use it. This should be pretty simple for most of you guys to do, I'm a Linux newbie. Cut me some slack lol.
 
Old 07-27-2013, 08:04 PM   #2
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Code:
$ USER_CNT=`who | cut -f1 -d ' ' | sort -u | wc -l`
$ let "result = 100 / $USER_CNT"
$ echo $result
 
Old 07-27-2013, 08:05 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Using 'cut' and 'sort' takes care of users that are logged in multiple times or have multiple terminal windows open (if they are accessing your system via a GUI).
 
Old 07-27-2013, 08:07 PM   #4
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by Expedient View Post
This should be pretty simple for most of you guys to do, I'm a Linux newbie. Cut me some slack lol.
I was wondering about that. You can write multi-threaded C programs, but not do simple math in the shell. Whatever, the above should work for you. Good luck!
 
  


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: how to divide complex : FINAL=`[ ($var2 - $var1 ) / $var1 * 100 ]` frenchn00b Programming 9 11-06-2008 10:04 AM
managing the amount of data that is logged paranoid times Linux - Security 3 02-09-2007 02:46 PM
Make most amount of Linux users in least amount of time studpenguin General 24 02-02-2007 03:42 PM
Control amount of time a user may be logged in. (Parental Control) darrensnospam Mandriva 13 02-18-2006 05:01 PM
How to check amount of users logged in CurtisKaj Linux - General 4 08-20-2003 09:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:21 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