Programming :: Script To Search And Count Hits From Some Country
Mar 25, 2011
I need something to make a script that will search some logs and extract IP hits from one country only. Let's say UK. I guess I need to use GeoIP or some database. I just need a very simple bash, perl, php script that will do this job. Just search threw logs (apache) and then give me number of hits found from UK.
View 5 Replies
ADVERTISEMENT
Feb 1, 2011
I have written a code on Linux that searches a long dictionary. I have used hsearch() function but the problem is it does not work. This is my code://Search the count values from the dictionary.
Code:
#define _GNU_SOURCE
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<search.h>
#include<inttypes.h>
#include<math.h>
[Code]...
I open each DIC file, get the word from it and search the hash table and extract the key from it. The problem with the above code is that it is able to make the hash table but it returns NULL when searching. It should not return NULL in any case because all words from DIC files are there in the dictionary. I am not able to figure out why?
View 1 Replies
View Related
Feb 24, 2010
I have the following perl/DBI script:
Quote:
#!/usr/bin/perl
use DBI;
my ($db, $user, $pw) = ('dbname', '****', '***********');
my $dbh = DBI->connect("DBI:mysql:$db",$user,$pw) or die "Cannot connect to $db: $DBI::errstr
[code].....
The error message is
[Wed Feb 24 13:03:27 2010] myscript.cgi: DBD::mysql::st execute failed: Column count doesn't match value count at row 1 at myscript.cgi. [Wed Feb 24 13:03:27 2010] myscript.cgi: DBI::db=HASH(0x8a30c60)->errstr
View 2 Replies
View Related
Oct 25, 2010
My script looks really crap and messy, the logic isn't great and I'm not hugely happy with it. Also it echo's $i instead of an actual IP address (line 10). How to improve this. It basically searches through /var/log/messages for multiple FTP hits and when the hit count is higher than a specific number the IP is added to a config file and ftp is restarted. There are some obvious flaws in my script.
Code:
MAXHITS=0
TOPHITS=`grep "FTP session closed." /var/log/messages* | awk '{print $7}' | sed -e 's/^.*[//' -e 's/].*$//' | uniq -c | sort -nr`
HITNUMB=`echo $TOPHITS | awk '{print $1}'`
IPHIT=`echo $TOPHITS | awk '{print$2}'`
HIGHIP=`echo $TOPHITS | grep $HITNUMB | grep $IPHIT | awk '{print $2}'`
if [ $HITNUMB -gt $MAXHITS ]; then
for i in $HIGHIP;
do
echo $i
sed -i '78s/$/,$i/' /opt/etc/proftpd.conf
/root/ftp restart
done
else
echo "not greater than $MAXHITS"
fi
I'm not even sure what will happen if I get multiple responses for my $TOPHITS. It would be cool if it could search for IP's already blacklisted somehow, it might actually be easier to just create a file with a set of blacklisted IP's or something.
View 14 Replies
View Related
Dec 20, 2010
I have a list of 2 character country abbreviations used in the Maxmind GeoCountry database that I need to convert to the standard 3 character country abbreviation ISO 3166-11 format. I could have a long list of sed substitute statements for each country.
Code:
sed "s/US/USA/g" <file>
Is their a more elegant way to do this? Maybe an array of some sort? This substitution will be used in a bash script.
View 4 Replies
View Related
Jan 11, 2011
I want to count the number of files in each sub folder of a directory structure. At the moment I can do:
ls -1R /Folder | wc -l
Which lists the item count for all the folders as one. I can do:
ls -1R /Folder wc l
Which lists all the folders in the top level and all the items. Is there any way to get the list of folders and then item count for each folder?
View 1 Replies
View Related
Nov 9, 2010
I have these but not working.
size_t count_words(const std::string& s)
{
std::istringstream is(s);
return distance( std::istream_iterator<std::string>(is),
std::istream_iterator<std::string>());
}
and
std::string s; // word count
unsigned int wordno = 0;
while(getline(myfile, s))
{ ++wordno;
if(s.empty())++ wordno;
else wordno += count_words(s);
std::cout << s << '
';
}
myoutput1<< "Number of words : " << wordno << '
';
myoutput1 << "
Word" <<" " <<" Occurrence" <<endl;
myoutput2<< "Number of words : " << wordno << '
';
myoutput2 << "
Word" <<" " <<" Occurrence" <<endl;
View 6 Replies
View Related
Jul 8, 2009
I need to count files in a dir which were updated yesterday.
ls -lth | grep -i 'Jul 7' | wc -l
The dir holds files of last 15 days and total count is as 2067476. Is it efficient to count the files using perl? I have developed the following perl script making use of system().
Code:
#!/usr/bin/perl
@months = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
($sec,$min,$hour,$monthday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
[code]....
View 12 Replies
View Related
Nov 29, 2010
I have log files that should be parsed and then deleted by a script on a regular basis. Sometimes things don't work for a variety of reasons and the log files sit and sit and are never dealt with. What I need is a small script that can give me the files older than X days and a count of those files.
What I have so far helps me take care of things manually but I need a little automation in my life Here is what I have: I can count all the files in the necessary directories recursively with this: ls -laR | wc -l And I can find all the files that are older than 10 days that haven't been deleted yet by doing this: find /home/mike/logs -type f -mtime +10 But how do I put both of them into a script that will just give me the end number of both?
View 5 Replies
View Related
Apr 7, 2011
Word Count for all files in a directory
View 1 Replies
View Related
Jan 18, 2010
I have a file with lines that look like this:
Dev/7_Texas2004/4_Caves/page.htm
Dev/7_Texas2004/5_SanMarcos/page.htm
Dev/7_Texas2004/6_Austin/page.htm
And I'm trying to count the number of slashes in each line. I figured (with my limited knowledge of bash) that the best thing to use would be sed. So I ran this to print "not /": sed '!s////g' file # and eventually adding " | wc -m" to it. and I got the same result as if I ran cat, no modification at all:
[Code]...
View 7 Replies
View Related
Jan 7, 2011
I need to search through HTML files to count the number of <li> tags nested within the first <ul> tag:
Code:
<ul>
<li>text 1</li>
<li>text 2</li>
</ul>
...
<ul>
[Code]...
Unfortunately, the second grep is greedy swallowing everything up to the last </ul> close tag. (The desired result is 2.) Speed is an issue as I will be searching through 350,000 files.
View 14 Replies
View Related
Jan 26, 2011
How do I count the number of occurrence characters in a string in an efficeint way ?
How do I reverse the words in a string with out using temp variables if possible . (if not possible use temp variables ?
Why do I specify dependedcies for header files in the Makefile ?
View 2 Replies
View Related
Jun 11, 2010
I am using RHEL 4.5.
I am trying to count no. of characters in a word but it is coming one more than what it actually should be.
Code:
I can have a work around by subtracting 1 from the output (6-1=5 in this case). BUT, I am just curious to know, why the character count is coming as 6 and not 5.
View 7 Replies
View Related
Jun 3, 2011
im stuck with something trivial again. so i want to calculate how much time my programm runs:
int main (int argc, char* argv[])
{
clock_t end, start;
start= clock();
int i;
int p, q, r;
FILE* f_out_loc;
[Code]....
it returns 1.12 sec. looks like clock() doesnt count how much system() works .... is it possible? and how do i calculate the whole thing?
View 4 Replies
View Related
May 10, 2010
Exist it a perl function to count how much each array element is into array?
View 14 Replies
View Related
Jul 15, 2011
What I want to do is from a file having block like
<event>
8 3 0.2685416E-02
2 -1 0
21 -1 0
[code]...
The first line after the "<event>" is its process-id, so I would like to have at the end a summary of how many "event" block I have for each type, ie how many
6 1 0.2685416E-02
or how many
7 2 0.2685416E-02
etc etc
I do not know in advance how many different-kind of block I will have, so it has to be a bit smart to scan the file, and make an new "summary" info for each unique type I was using something like
awk '/<event>/,/</event>/{if ($3 -eq 0.2685416E-02 ) { print $1" "$2" "$3}}' file > out
and then
grep -c "$1" "$2" "$3" but with no success since my awk commands prints all lines of each block
Suppose, that in advance I do know the $3, ie the 0.2685416E-02 which is a kind of weight
View 8 Replies
View Related
Apr 28, 2011
I love medit for text editing, but it's missing a word count feature.
I found a "Statistics for medit" script on the Arch Linux Forums, but after installing as instructed, there was no popup.
So I set it to output to a pane instead, and I got:
Code:
My scripting skill is extremely basic, so any troubleshooting. (I'm using CrunchBang Statler, which is Debian Squeeze based.
View 6 Replies
View Related
Feb 25, 2010
I'm working on a bash script that will go through a directory, find the sub-directories that have been created since the last time the script ran, count the results, and output that integer (will most likely be '1' or less per each instance run) to a file. Give the circumstances, my previous (and very limited) experience with bash is not sufficient for me to pull this off. since it probably has bearing, is that my mail server stores files that it flags as viruses in a folder. It creates a sub-directory for each virus that it quarantines .I want to count those subdirectories and graph them with MRTG. Hence the script. I'm going to post what I've got so far and the purpose of it, because I'm told I have a very odd and efficient way of doing scripting.
[Code]...
But then it dawned on me that it wouldn't work because I would have to not count the directories that have already been counted and count the ones that have not been counted. Given that the purpose of this is to generate a graph about every 5 minutes, using find won't work because, to my knowledge, that will only find things based on whole day values, I need it almost down to the minute.
View 1 Replies
View Related
Apr 7, 2010
I am trying to get the count of number of CD-ROMs attached with my Linux system using a bash shell script. I have decided to use the following method for it:
Code:
debian:~# cat /proc/sys/dev/cdrom/info | grep "drive name:"
drive name: sr0 hdb
So basically I know that there are two CD-ROMs attached to the system. Now there can be three also like this:
Code:
debian:~# cat /proc/sys/dev/cdrom/info | grep "drive name:"
drive name: sr0 sr1 hdb
All I want to do is in my shell script to get the count of the devices in a variable using the above command.
View 2 Replies
View Related
Aug 26, 2010
I am new to perl scripting and wrote a perl script to read the directories and files and count the no of files in each directory and generate a log file. The problem is it is not printing anything to the log file. I am copying the script below.
!/usr/local/bin/perl
$dir= 'c:My ProjectsPerl ScriptsNew Folder' ;
$directory_count = 0;
$file_count=0;
[code].....
View 14 Replies
View Related
Oct 23, 2010
I'm using MYTHTV with AT&T's U-Verse system. AT&T apparently turns off the set-top box if the box doesn't receive any commands after some number of hours. When this happens the box takes so long to turn on that it doesn't process the lirc IR channel change command. I've rewritten my channel changer to add a lockfile, and added a cron entry to kick off an entry to just "ping" the set-top box once an hour. But, OK, I'd like to play the bandwidth saving game and not do this if there isn't anything in the "record" table.
So, how would I write a script that will check the number of rows in the "record" table in the "mythconverg" database and exit if there are zero rows? I'm afraid I don't know how to even start this. Here is my "keepalive.sh" script that does the pinging:
Code:
#!/bin/sh
#if there are no rows in the record table, just exit this script
# lock the lockfile - MUST be same one as channel lock
while [ `lockfile "/tmp/mythchanlock.lck"` ]
[Code]....
View 3 Replies
View Related
Aug 11, 2010
I would like to parse an input file in which there are two columns per each row. We want to see how many lines are duplicated where we define duplicate to be having the same second field and different first field. For instance if the input file looks like the following:
79874 13131
79873 12309
79820 13131
[code]...
View 10 Replies
View Related
Jun 8, 2011
When vlc 1.1.10 hits natty, this is a minor security and bugs update so it should arrive soon officially?
View 5 Replies
View Related
Oct 5, 2010
How can i use grep (or any other command) to check for lines that begin with N number.
E.g. I want to print out commands (from history), but only from the command number 50 until #200.
This one doesn't work:
Code:
history | grep "^[50-200]"
Should print out something like:
Code:
50 cd ~/Desktop
[Code].....
View 4 Replies
View Related
Feb 3, 2010
How to search for a file? I am looking for a file in a directory /shared/domain...This also contains many sub directories..I need a script which will let me know the location of my log file myapps.log.what is the script ?Can it be made in one line ...because I just want to run ...don't want to save the script.
View 14 Replies
View Related
Jan 21, 2010
Code:
Title=
echo -n "Title: "
[code]...
hey guys, im doing a simple search program and i came up with a problem. What i am trying to achieve is, if the search is false(means the book does exist) , the program will then ask the user to input the information again(title and author) and do a search again until there is no such book and then display a message saying he can input a new book in.i tried using a until loop, but it does not seem to work. some guidance on how the statement should be and where should it be placed?
View 4 Replies
View Related
Jan 16, 2011
I am trying to see whether wget can be used to generate actual url hits on a webpage. This does not look good so far�. I changed the following lines in /etc/wgetrc to:
Code: http_proxy=http : / /<proxy_ip>:<port>/ use_proxy on Output :
Code: root# wget -c <url>/ > /dev/null
--2011-01-16 12:26:38-- <url>
Connecting to <proxy_ip>:<port>... connected.
[code]....
2011-01-16 12:26:39 (88,9 KB/s) - `index.html.3' saved [50548] This does NOT generate a hit on the actual web page! It does not seem like the, > /dev/null part is working either... How can I get this to work?
View 4 Replies
View Related
Apr 19, 2011
I am in need to create a script that queries how large a partition is and when it hits a certain percentage (say 90%) it will execute another script that tars up certain files (or they could just be part of the same script). I would create a cronjob that runs this script once a day.
I have the script that tars up the files I need, sets permissions, etc. (btw, the files in question are audit logs). I just need the part that runs something like a df -h and takes the use percentage of the /var partition in that query and if that percentage is greater than/ equal to 90%, it kicks off the tar script.
Here is a sniplet of the df -h with just the /var partition shown:
Quote:
So, when the cronjob sees that the Use% is >= 90%, it would kick off the tar script...if not above 90%, it closes.
View 14 Replies
View Related
Jun 13, 2011
I have ASCII files to parse that 48 hours old or more ; I can identify them like so
Code:
find . -name "FILE*TXT" -mtime +1 -exec ls -ltas '{}' ';'
Some files have a list of hardware errors (we test electronic components), some have none. If the file name has no errors, I still want to display a message like so
Code:
grep ^err R*VER && echo "No error"
FILEA.TXT:err->USB3910err
FILED.TXT:err No Error
This grep statement works but it seemingly overrides the find() statement above if I run both at the same time... How can I combine the two statements to create a report that lists the filename and error(s) like so
Code:
FILEA.TXT Button3320err
FILEB.TXT USB3235err
FILEC.TXT IR Remote2436err
FILED.TXT No error
Is it possible to return "No error" with the file name without error?
View 11 Replies
View Related