The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sh, Bourne Problem with getting lines in a file kdyzsa Shell Programming and Scripting 1 05-08-2008 11:28 PM
Project with somewhat simple bourne shell cript.. Generic UNIX for Dummies Questions & Answers 17 04-15-2008 03:06 AM
please give a bourne script to this problem raj1811 Shell Programming and Scripting 1 09-30-2006 04:36 PM
simple bourne script catbad Shell Programming and Scripting 2 03-24-2003 11:36 AM
bourne mail script problem Priest_Ridden Shell Programming and Scripting 6 12-12-2001 01:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-08-2003
pnxi pnxi is offline
Registered User
  
 

Join Date: Sep 2003
Location: Austrailia
Posts: 14
Red face simple Bourne problem

Hi, I'm a newer for this languages, and I have a log file, which is something like this:
Code:
35.75.253.207 - - [17/Aug/2003:12:42:37 +1000] "GET /products/orgonizer/title.png HTTP/1.1" 200 1555 "-" "Mozilla 1.4"
Now, I want to write a shell code to accoplish like ./XXX.sh -N n
n is a number by user input, the code should print the n most popular files, if -I, i should ignore all the .gif,.jpg, .jpeg, .png files(I know using AWK field '{print XX}' to accoplish this.) and -S, it ignores lines in the log whose status code is not 200. (200 in above line means successful access) and how let the program can allow batch operation, like -NIS XXX or -NI XX etc.
Here is my work so far:

Code:
 log_sort()
{
     awk '{print $7}' access.log.1 | sort -k 1 |  uniq -c | sort -ur -o   tmp.txt
  head -n 10 tmp.txt
  rm tmp.txt
}
log_sort_N()
{
  awk '{print $7}' access.log.1 | sort -k 1 |  uniq -c | sort -ur -o tmp.txt
  read $3
  head -n $3 tmp.txt
  rm tmp.txt
}
#main function goes here
if [ $# = 1 ]; then
     log_sort
elif [ $# = 3 ]; then
      read $2
      if [ $2 = "-N" ]; then
        log_sort_N -3   
   fi
fi
  #2 (permalink)  
Old 09-08-2003
norsk hedensk norsk hedensk is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
here is what i used for a script i wrote for command line option checking. its right from my script so you will have to edit it your self for your needs. also i got the outline of this from tldp.org's advanced bash shell scripting guide

Code:

NO_ARGS=0
E_OPTERROR=65

if [ $# -eq "$NO_ARGS" ] # should check for no arguments
then
	echo "Usage: `basename $0` -s<OPTIONS> <HOSTNAME> "
	echo "You must specify interactive, or non interactive mode for now"
	echo "Try './serverstatus -h' for more information."
	exit $E_OPTERROR
fi

while getopts ":sinvh" Option
do
	case $Option in

		s )
			hostname=`echo $@`
			hostname2=`echo $hostname|awk '{print $2}'`
			echo $hostname2
			a=`nmap $hostname2`

		;;

		i )
			interactivemode_func
		;;

		n )
			non_interactivemode_func
		;;

		v )
			version_func
		;;

		h )
			help_func
		;;

		* )
			echo "Unimplemented option chosen"
		;;
	esac
done

shift $(($OPTIND - 1))
i put that in a function called main() and called the function with

Code:
main "$@"

credit to perderabo for showing me that last part, i dont think i would ever have figured that out without his help.
  #3 (permalink)  
Old 09-09-2003
pnxi pnxi is offline
Registered User
  
 

Join Date: Sep 2003
Location: Austrailia
Posts: 14
Unhappy How to exclude the .jpg, .gif file

I still doesn't know any command to allow me the exclude the .jpg, .gif file from the whole log list. any body knows
  #4 (permalink)  
Old 09-09-2003
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 500
Would this happen to be an apache log file that you are playing with ??
  #5 (permalink)  
Old 09-09-2003
pnxi pnxi is offline
Registered User
  
 

Join Date: Sep 2003
Location: Austrailia
Posts: 14
Unhappy yes

yes, please help me!
  #6 (permalink)  
Old 09-09-2003
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 500
I thought as much - something jumped out.

I've done this before for a client in a previous position - removing images from being logged can reduce logfile size.

I'll give you this link: http://httpd.apache.org/docs-2.0/logs.html#accesslog

From that you sould be able to figure it out - so you can forget the scripting - you don't need it.

Concentrate on the httpd.conf file (and/or httpsd.conf for SSL - me thinks).

Best of luck.

Another example : http://httpd.apache.org/docs-2.0/env.html#examples
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0