Sponsored Content
Top Forums Shell Programming and Scripting Recorder number of process per user Post 302949000 by Don Cragun on Sunday 5th of July 2015 08:45:42 PM
Old 07-05-2015
You can simplify your pipeline a little bit... The uniq won't reorder the output, so the second sort isn't needed. Also note that the standards don't clearly specify what happens when both the -f option and the -o option to ps are given (they place conflicting requirements on the output format; so specifying both is non-portable).

Putting your code in a loop to run your command line (and add a timestamp to the start of each line) is pretty easy. If you start the following script at 10am, by default it will produce reports at about 10:00, 10:15, 10:30, 10:45, 11:00, 11:15, 11:30, 11:45, and noon and then quit. If you pass arguments to the script you can change the number of minutes between samples and the number of samples to be run. It was a written and tested using a Korn shell, but will work with any shell that meets basic POSIX conforming shell requirements for arithmetic and variable expansions.
Code:
#!/bin/ksh
# Usage: counter [ repetition_count [ minutes_between_samples ]]
# Count and report number of processing running for each user.
reps=${1:-9}	# # of samples to collect (default: 9 samples)
delay=${2:-15}	# minutes between samples (default: 15 minutes)

printf "Gathering $reps samples $delay minutes apart\n"
while :
do	DandT=$(date '+%m/%d/%y    %H:%M')
	printf 'Date        Time     User                Num_Proc\n'
	ps -A -o user|sort|uniq -c|while read count user
	do	[ "$user" = "USER" ] && continue
		printf '%-20s %-20s %7d\n' "$DandT" "$user" "$count"
	done
	reps=$((reps - 1))
	[ "$reps" -le 0 ] && break
	echo
	sleep $((delay * 60 - 2))
done

 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

number of process?

how i know number of process are currently run on my user area (2 Replies)
Discussion started by: piyush_movadiya
2 Replies

2. UNIX for Advanced & Expert Users

number of process

Hi, under AIX 5.2 which (environment) parameter defins the number of processes for the server ? Many thanks. (2 Replies)
Discussion started by: big123456
2 Replies

3. Infrastructure Monitoring

System Data Recorder

Monitoring the IT infrastructure is an important key to ensure your business continuity and prepare for future grow. SDR is a simple toolkit, containing a number of data collectors, used to record and report data from your Solaris servers. SDR is mainly designed around Solaris operating system due... (0 Replies)
Discussion started by: Linux Bot
0 Replies

4. Solaris

Number of process per user session

Hi All, Do we have any option through which we can limit the number of process which can be started by single user session. Thanks (3 Replies)
Discussion started by: kumarmani
3 Replies

5. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

6. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

7. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies
pridist.d(1m)							   USER COMMANDS						     pridist.d(1m)

NAME
pridist.d - process priority distribution. Uses DTrace. SYNOPSIS
pridist.d DESCRIPTION
This is a simple DTrace script that samples at 1000 Hz which process is on the CPUs, and what the priority is. A distribution plot is printed. With priorities, the higher the priority the better chance the process (actually, thread) has of being scheduled. This idea came from the script /usr/demo/dtrace/profpri.d, which produces similar output for one particular PID. Since this uses DTrace, only users with root privileges can run this command. EXAMPLES
This samples until Ctrl-C is hit. # pridist.d FIELDS
CMD process name PID process ID value process priority count number of samples of at least this priority BASED ON
/usr/demo/dtrace/profpri.d DOCUMENTATION
DTrace Guide "profile Provider" chapter (docs.sun.com) See the DTraceToolkit for further documentation under the Docs directory. The DTraceToolkit docs may include full worked examples with ver- bose descriptions explaining the output. EXIT
pridist.d will sample until Ctrl-C is hit. SEE ALSO
dispadmin(1M), dtrace(1M) version 0.90 Jun 13, 2005 pridist.d(1m)
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy