Sponsored Content
Top Forums Shell Programming and Scripting Script to find the top 100 most popular pages Post 302518650 by jontjioe on Sunday 1st of May 2011 12:13:57 AM
Old 05-01-2011
Ok, I got it working. I split up the problem and I was able to figure it out...just took me a while. Here it is for those who are interested. I left all of the pages instead of just keeping the top 100.

Thanks!

Code:
#!/bin/bash
#===============================================================================
# 
#===============================================================================
#@| SYNOPSIS
# |
#-|   Filename: findPopularPages.sh
#-|   Version:  1.0 
# |
#-|   Purpose:
#-|            This script finds the popularity of pages of a disksim
#-|            formatted trace file.
#-|
#-|   Inputs:  Real world trace file in the DiskSim format
#-|
#-|   Outputs: Prints trace statistics to screen
#-|
#------------------------------------------------------------------------------
#@| REQUIREMENTS / DEPENDENCIES / ASSUMPTIONS
# |
#------------------------------------------------------------------------------
#@| REVISION HISTORY
# |
#-|   Date Created/Revised: 4/30/2011  Author/Revisor: Jonathan Tjioe
#-|   STR #:  Bug ID:  Description:
#-|   1.0  Jonathan Tjioe (4/30/2011)
# |
#===============================================================================

FILE=$1
SCRIPT=findPopularPages.sh
PWD=`pwd`

printf "\nStarted $SCRIPT on $FILE at:\t\t `date`"

#Only print the Write requests ($5==0)
removeReads() {
cat $FILE | awk '$5==0 {print $0}' > TEMP1
}

#The LBA must start at a block address that is divisible by 4
#The size must be in multipes of 4
adjustBlockAndSize() {
cat TEMP1 | awk '$3=(int($3/4)*4)' |awk '{
if (($4%4)!=0) {print $1" "$2" "$3" "((int($4/4)*4)+4)" "$5}
else {print $0} }' > TEMP2
} 

#Need to save a list of all of the pages for each line
createPageListing() {
cat TEMP2 | awk '{for (i=$3; i<($3+$4); i+=4) {print i}}' > TEMP3
}

#Count how many times a page was written to
countUniquePages() {
cat TEMP3 | awk '{count[$1]++} END {for(i in count) print i, count[i]}' > TEMP4
}

#Sort the pages by the most popular in descending order
sortPopularity() {
cat TEMP4 | sort -nr -k2 > ${FILE}_mostPopularPages
}

#Delete temporary files
cleanUp() {
rm TEMP1 TEMP2 TEMP3 TEMP4
}

############## Start of Main ##############
removeReads
adjustBlockAndSize
createPageListing
countUniquePages
sortPopularity
cleanUp
############## End of Main ################

printf "\nFinished $SCRIPT on $FILE at:\t\t `date`\n\n"
exit 0

 

10 More Discussions You Might Find Interesting

1. AIX

How to find the top 6 users (which consume most space)?

Hi everybody, I want to know if there is any posibility to find out - on an AIX system - which are the the users who consume most space or at least a posibility to obtain a list with all the users and how much space are they consuming ? Trying to use du command was useless. Any idea?... (5 Replies)
Discussion started by: RebelDac
5 Replies

2. Shell Programming and Scripting

How to exclude top level directory with find?

I'm using bash on cygwin/windows. I'm trying to use find and exclude the directory /cygdrive/c/System\ Volume\ Information. When I try to use the command below I get the error "rm: cannot remove `/cygdrive/c/System Volume Information': Is a directory. Can someone tell me what I am doing... (3 Replies)
Discussion started by: siegfried
3 Replies

3. Cybersecurity

Recursively find and change Permissions on Man pages

Just joined after using the site as a guest.. (Very Good Stuff in here.. thanks folks.) I am in the process of hardening a Solaris 10 server using JASS. I also must use DISA Security Checklists (SRR) scripts to test for things that did not get hardened to DISA standards. One of the things... (5 Replies)
Discussion started by: altamaha
5 Replies

4. Shell Programming and Scripting

find top 100 files and move them

i have some 1000 files in my dir and i want to find top 100 files and move them to some other location: below the 2 commands i used, but it is not working ls -ltr | grep ^- | head -100 | xargs mv destination - _________>not working ls -ltr | grep ^- | head -100 | xargs mv {}... (3 Replies)
Discussion started by: ali560045
3 Replies

5. UNIX for Dummies Questions & Answers

find the size of a database by counting all the used pages

Hi all, I am looking to find the size of the database by counting all the used pages. 1. I have a file which reads like below 16384 4750850 32768 165 The first column is the pagesize and the second column is the number of pages... (6 Replies)
Discussion started by: family_guy
6 Replies

6. Programming

code to find the top of the stack, not able to figure it out

OFFSET=100; PAGESIZE=4096; int dummy_last; TOPSTACK = (caddr_t)(&dummy_last - OFFSET); TOPSTACK = (caddr_t)((unsigned long)TOPSTACK - ((unsigned long)TOPSTACK % PAGESIZE)); this i a code to find the top of the stack, but not able to figure it out. can... (2 Replies)
Discussion started by: holla4ni
2 Replies

7. Shell Programming and Scripting

find top 4 users currently logged on can i use grep

For the first 4 users only that are currently logged in output their effective user id. It's not important the order in which each logged in i just want to have the top 4. Same question as here...... (0 Replies)
Discussion started by: whyatepies
0 Replies

8. UNIX for Dummies Questions & Answers

how to find top 3 users currently logged on

For the first 3 users only that are currently logged in output their effective user id. thank you. (6 Replies)
Discussion started by: whyatepies
6 Replies

9. Red Hat

How to find memory taken by a process using top command?

I wanted to know how to find the memory taken by a process using top command. The output of the top command is as follows as an example: Mem: 13333364k total, 13238904k used, 94460k free, 623640k buffers Swap: 25165816k total, 112k used, 25165704k free, 4572904k cached PID USER ... (6 Replies)
Discussion started by: RHCE
6 Replies

10. UNIX for Dummies Questions & Answers

Find and cat top lines recursively

I have a folder structure with multiple sub directories MAIN FOLDER1 SUBFOLDER1 files...... FOLDER2 SUBFOLDER1 files...... etc and I want to find a way to create an output of every files first 20 lines. I've been searching and testing and failing. I can do it in a... (2 Replies)
Discussion started by: darbs121
2 Replies
trace(1)						      General Commands Manual							  trace(1)

Name
       trace - trace system calls of programs

Syntax
       trace [options] cmd args...

Description
       The  command  with  no flag arguments traces for the given cmd and args all system calls made and prints a time stamp, the PID, call and/or
       return values and arguments and puts its output in the file trace.dump.

Options
       -f filename
	       Puts dump in file filename.

       -z      Echos arguments only.

       Only one of the following option arguments can be specified at one time.

       -c#     Traces given PIDs and their children.  Up to sixteen PIDs can be specified.

       -g#     Traces given groups only.  Up to sixteen Group IDs can be specified.

       -p#     Traces given PIDs only.	Up to sixteen PIDs can be specified.

       -s#     Traces given system calls only.	Up to sixteen PIDs can be specified.

       -u#     Traces given UIDs only.	Up to sixteen PIDs can be specified.

Examples
       trace -f ls.dump ls -l /dev >ls.out
       runs the cmd ls -l /dev and puts the trace in ls.dump and output in ls.out.
       trace -f csh.trace -p $$ &
       will trace your login shell in the background. To stop the trace just send it a termination signal (that is, kill -TERM trace_pid).

Restrictions
       Due to security, no one, not even the super-user can trace anyone else's programs. This sort of negates some of the usefulness  of  the	-g
       and -u flags.

       The program cannot be traced.

       Only 16 numbers can be given to the -c, -p, -g, -u, and -s flags.

       The kernel configuration file must contain the following:
       options	       SYS_TRACE
       pseudo-device   sys_trace

       In addition, the superuser must use the following command sequence to create the device:
       cd /dev
       MAKEDEV trace
       If both lines are not in the configuration file or if the device is not made, the message "Cannot open /dev/trace" appears.

Files
       /dev/trace     read only character special device for reading syscall data.

       trace.dump     default file for the system call trace data.

See Also
       open(2), close(2), ioctl(2), select(2), read(2), trace(5)

																	  trace(1)
All times are GMT -4. The time now is 08:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy