simple Bourne problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple Bourne problem
# 1  
Old 09-08-2003
Power 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  
Old 09-08-2003
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  
Old 09-09-2003
Data 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  
Old 09-09-2003
Would this happen to be an apache log file that you are playing with ??
# 5  
Old 09-09-2003
Data yes

yes, please help me!Smilie
# 6  
Old 09-09-2003
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. Smilie

Another example : http://httpd.apache.org/docs-2.0/env.html#examples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

bourne script problem

I've got an NTFS file system mounted on my Linux box, which means I can have multi-word directory names. I want to recurse through the directory structure copying stuff from /A to /B when it does not already exist on /B. Here is the chunk of code, and the output of a set -x run on that chunk of... (8 Replies)
Discussion started by: esmith92000
8 Replies

2. Shell Programming and Scripting

simple wc problem

Hi there, Im sure there is a simple explanation for this but I have a file like this with no balnk lines peter paul john I run the command # var=`grep paul file.txt` # echo $var paul # echo $var | wc -l 1 but when I grep for a value that isnt in the file, i still... (4 Replies)
Discussion started by: rethink
4 Replies

3. Shell Programming and Scripting

Bourne Shell - Problem with while loop variable scope.

Hello I am having issues with a script I'm working on developing on a Solaris machine. The script is intended to find out how many times a particular user (by given userid) has logged into the local system for more than one hour today. Here is my while loop: last $user | grep -v 'sshd'... (7 Replies)
Discussion started by: DaveRich
7 Replies

4. Shell Programming and Scripting

Please help me with a simple problem

Hi, I have a very simple script like below: for n in 10 20 30 do for a in 30 40 50 60 70 80 do for r in 2 3 4 5 6 7 do m=$((r*a)) count=1 while do echo "a = " $a ", m = " $m ", n = " $n ... (2 Replies)
Discussion started by: Dark2Bright
2 Replies

5. Shell Programming and Scripting

if loop problem in bourne shell

how to use if-loop in bourne shell with multiple conditions like follows if then commands fi it gives me an error test: ] missing then i put if ] it gives me an error [[ not found kindly i need the syntex for the bourne shell (5 Replies)
Discussion started by: ahmad.diab
5 Replies

6. Shell Programming and Scripting

Sh, Bourne Problem with getting lines in a file

This is a new exercise for me 1.) Create a bourne shell script that can accept 2 arguments/parameters. Name your script as housekeep_files.sh. 2.) The script will delete the files specified in the input file (1st parameter) and will send a notification through email (2nd parameter) the... (1 Reply)
Discussion started by: kdyzsa
1 Replies

7. UNIX for Dummies Questions & Answers

Project with somewhat simple bourne shell cript..

Right now if I have a file that has the following information (with : as the delimiter) name :address :phone number I need to be able to do the following commands: -n search for a name -p search for a phone number -l search for a last name starting with a particular -c find an... (17 Replies)
Discussion started by: Generic
17 Replies

8. Shell Programming and Scripting

please give a bourne script to this problem

Hello all, I am new to unix and having the below problem.Any help will be appreciated. Write a Bourn shell script dTOe which takes as an input any number between 0 and 999 and prints the English value for this number. The program should display an error message when a NOT digit value entered.... (1 Reply)
Discussion started by: raj1811
1 Replies

9. Shell Programming and Scripting

simple bourne script

Hello There, I am trying to write this SIMPLE script in Bourne Shell but I keep on getting a blank response. Can you see what I am doing wrong? I am simply trying to take the day of the week from our system and when the teachers sign on I want them to see the message of the day, when they exe... (2 Replies)
Discussion started by: catbad
2 Replies

10. Shell Programming and Scripting

bourne mail script problem

Hey there, Just have a quick question. i've written a program and it needs to send a email to confirm it's completed. now i've done the mail -s "Subject" test@test.com the problem is the program, when run just waits. it doesn't execute the next command unless i press ^D. is there away... (6 Replies)
Discussion started by: Priest_Ridden
6 Replies
Login or Register to Ask a Question