LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help with advanced tar, ls, and egrep command... (https://www.linuxquestions.org/questions/linux-newbie-8/help-with-advanced-tar-ls-and-egrep-command-709390/)

jademan83 03-05-2009 09:55 AM

Help with advanced tar, ls, and egrep command...
 
I am migrating users off of a Linux mail server and need to grab the "password" files that the 3rd party mail software package uses for each user. Here is the scenario:

/var/*mail-program*/Accounts/user1.ext
/var/*mail-program*/Accounts/user2.ext

Inside the user#.ext file (text file) is a "LastLogin" date, and I would like to only grab those users that have logged into the mail this current year. On top of that the mail file is in the same directory and I only want to grab the password file. After that if I can tar the files, to send them to another server that would be great.

Has anyone used any deep ls / grep / egrep / tar commands for similar operations?

Any help would be appreciated.


Thanks

int0x80 03-05-2009 12:28 PM

Code:

#!/bin/bash
# Asserting that user1.ext corresponds to user1.password
# Get the user files for people who have logged in this year
mkdir /tmp/password_files
for user in $(grep 'LastLogin' /var/mail-program/Accounts/*.ext | grep 2009 | awk -F: '{print $1}'); do
    cp -p ${user:0:${#user}-4}.password /tmp/password_files
done
tar cjvf /tmp/password_files.tar.bz2 /tmp/password_files

for password_file in /tmp/password_files/*.*; do
    shred -vzu $password_file &
done
rmdir /tmp/password_files



All times are GMT -5. The time now is 07:38 AM.