Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-17-2009, 10:32 AM   #1
LQ Newbie
Registered: Aug 2003
Location: Florida
Distribution: Ubuntu
Posts: 12

Rep: Reputation: 0
Scripting ?, determine file type, compress, split and email

Source Aventail log files
Destination my email account

I do not have directed access to the Aventail servers or this would be easy. Inside of /var/log/aventail there are 10 files, one each for the last 10 days. They follow the standard .0, .1, .2 format so I am assuming they are not compressed. I would rather not assume but check the file type using file then compress them into 2 meg gz files and have them mailed.

Does anyone have a generic script that does something close to this? I think I can figure it out if I am pointed in the right direction.

file to determine file type
gzip to compress the file(s) (assuming it have a length argument)
command line like blat to send the mail.
Repeat for each server, currently 5

Old 01-17-2009, 11:24 AM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Here's a simple framework to start you out:

for FILE in /var/log/aventail/*; do

   case "$(file $FILE)" in

        *text* ) command1 $FILE | command2 ; command3 ;;

        * ) echo "not a text file" ;;


This will loop through all the files in the directory and test the output of file for the string "text", and runs the command1-3 string if it finds it, or echos an error if it doesn't. You'll have to shove this into another loop if you want it to check multiple servers.

If you need general scripting help there are lots of good bash scripting tutorials available on the net. The Advanced Bash Scripting Guide is one of the best.


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
Scripting ?, determine file type, compress, split and email edpatterson Linux - Newbie 2 01-17-2009 11:40 AM
Split large file in several files using scripting (awk etc.) chipix Programming 14 10-29-2007 12:16 PM
Compress and split a big sized file into smaller files hicham007 Programming 3 07-28-2005 09:56 PM
How do I determine file system type? lowpro2k3 Linux - General 5 07-09-2005 04:40 PM
How does KDE determine file type? vdemuth Linux - Software 4 01-08-2005 05:08 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:22 AM.

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