Bash: using file as input for grep/tail and then some..
Hi,
A bit of a background on the script I am trying to make first of all. I have a mysql database with some users in, I am taking a dump of the user table into a file, then I am using that file as the input to grep against the ftp log. I need to see the last 5 entries from the ftp log based on the user. For example: UserA: x.x.x9.x - usera.x.co.uk [31/May/2009:11:50:00 +0100] "PUT /home/uploads/usera/x.txt" 200 77 etc UserB: x.x.x9.x - userb.x.co.uk [31/May/2009:11:50:00 +0100] "PUT /home/uploads/userb/x.txt" 200 77 x.x.x9.x - userb.x.co.uk [31/May/2009:11:50:00 +0100] "PUT /home/uploads/userb/x.txt" 200 77 x.x.x9.x - userb.x.co.uk [31/May/2009:11:50:00 +0100] "PUT /home/uploads/userb/x.txt" 200 77 x.x.x9.x - userb.x.co.uk [31/May/2009:11:50:00 +0100] "PUT /home/uploads/userb/x.txt" 200 77 I also need to (somehow) run a query on the ftp log to find if someone hasnt uploaded data in the past 2 weeks. I also on top of this need to count how many times the username appears in the logs. The username is part of the /home/uploads/ also. The logfile rotation will be changed to rotate every 2 weeks with this script being ran about 12 hours before the log roates, but it will be ran on a weekly basis. I then require all the data to be put into one easy to read log for the managing directors to look at. Needless to say I have been thrown in the deep end and have never really used bash to this extent before. So far I have this, which is very messy but gets half the job done, I seem to have hit a wall (programmers block?) and cannot seem to find my way around it, any nudges in the correct direction would be very very useful. Code:
#!/usr/bin/env bash Any slight nudges or suggestions on what to do would earn my eternal gratitude! Thank you! |
Re: Bash: using file as input for grep/tail and then some..
I don't know about eternal gratitude, but I have never gotten one before, so it would be nice to get one just for the experience :-) Just kidding.
Here is a script: Code:
system mysql -h db.xxx.xxx.xx -u xxxxxx --password=xxxxxxx -e "use FTP; SELECT SUBSTRING_INDEX(user , '.', 1) AS username from users;" > users.txt Randi |
Moin,
first, the "(cat $UFILE)" is not necessary. The line "done <<$UFILE" should do it. To get the users, which do not appear in the ftp log, the "-v" option of grep is the wrong way. You'll get all lines NOT belonging to this user. You can use the -c or the -q options: Code:
if test `grep -c "$line" $UFILE` -eq 0; then ... |
Quote:
|
Quote:
Thank you |
Quote:
|
All times are GMT -5. The time now is 11:40 PM. |