![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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" 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
|
|
||||
|
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))
Code:
main "$@" credit to perderabo for showing me that last part, i dont think i would ever have figured that out without his help. |
|
|||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|