LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2009, 07:32 PM   #1
pdstu25
LQ Newbie
 
Registered: May 2009
Posts: 4

Rep: Reputation: 1
Need help with script to get user ftp logs


Hello,

I'm trying to write a shell script that will grab a users ftp logs and put it in his home dir. The server I will run this script on keeps two plan text logs and the other 6 are compressed with .gz. For example there is auth.log, auth.log.1 auth.log.2.gz ..... auth.log.8.gz I would like to scan all those plus xferlog (which is setup the same way) for a user and have it place a auth.log and xferlog file in the customers root. I have the below script which works but only does it for one file. All help is appreciated.

#!/bin/sh

DIR=/hsphere/local/var/proftpd/
USER=$1

if [ $# -eq 0 ]
then
echo "$0 : You must supply username"
exit 1
fi

if [ -f $DIR/auth.log ]
then
cat $DIR/auth.log | grep $USER >> /hsphere/local/home/$USER/auth.log
else
echo "File doesn't exist"
fi


P.S This is my first time posting to any Forum so please be gentle
 
Old 05-26-2009, 07:46 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Code:
for file in `ls $DIR/auth.log*`
do
    if [[ $file =~ "gz" ]]
    then
        zcat $file | grep $USER >> /hsphere/local/home/$USER/auth.log
    else
        grep $USER $file >> /hsphere/local/home/$USER/auth.log
    fi
done
NB: Untested as I don't have Linux in front of me. Also, you need bash >= v3 for regex "=~" operator.
http://www.tldp.org/LDP/abs/html/bas...#REGEXMATCHREF
 
Old 05-26-2009, 07:57 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by chrism01 View Post
[code]
for file in `ls $DIR/auth.log*`
no need ls.
Code:
for file in $DIR/auth.log*
 
Old 05-26-2009, 08:25 PM   #4
pdstu25
LQ Newbie
 
Registered: May 2009
Posts: 4

Original Poster
Rep: Reputation: 1
Thanks works exactly as needed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Have Proftpd run a script after user logs out derridking Linux - Server 0 04-01-2009 06:24 PM
How does ftp user logs ram_rajavarapu Linux - Server 2 10-16-2008 08:31 PM
What script runs when a user logs in? GuyWhoKilledBear Slackware 6 11-27-2006 10:58 PM
Automatic email sent when ftp user logs in joadoor Linux - Security 2 04-14-2006 12:20 AM
Automaticly run script when user logs in? bigdog0007 Linux - Security 3 06-23-2005 04:14 PM


All times are GMT -5. The time now is 01:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration