LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-21-2003, 11:09 AM   #1
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Rep: Reputation: 46
Question I need the syntax for emailing a log file.


I am trying to set up a cron job to automatically email me the log file for iptables (/var/log/messages). I think I have figured out the cron side of this. But what command from the CLI would email the file? Is there something else I need to set up to be able to do this?
 
Old 02-21-2003, 02:53 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
mail someone@somewhere.org < file
 
Old 07-18-2003, 11:18 AM   #3
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Original Poster
Rep: Reputation: 46
Thanks Mara. I set up a cron job to execute a bash script which mails the /var/log/maillog to my email address daily, and then deletes it from the server (to prevent it from growing too large). The problem now is that once it deletes the maillog, the file is not recreated with the same name unless the machine is rebooted. Is this a permissions issue? How can I make it ok for the log generator to recreate a new /var/log/maillog file?
 
Old 07-18-2003, 11:21 AM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
You may try to make the file empty (size: 0) and not to delete it.
 
Old 07-18-2003, 11:23 AM   #5
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Original Poster
Rep: Reputation: 46
Is there a command for deleting the contents of a file w/o deleting it? That would be cool. But wouldn't the user that runs the delete command automatically be the new owner of the file?
 
Old 07-18-2003, 11:56 AM   #6
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
cat /dev/null > /var/log/whateverlogfileyouwanttoempty
 
Old 07-18-2003, 12:05 PM   #7
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Original Poster
Rep: Reputation: 46
Cool. Thanks Blinker_Fluid. I will give that a shot..
 
Old 07-18-2003, 12:05 PM   #8
green_dragon37
Member
 
Registered: Oct 2002
Location: Lower Alabama
Distribution: Slackware, OpenBSD 3.9
Posts: 344

Rep: Reputation: 31
In shorter form:
Code:
: > /filetoempty
The ':' in bash scripting means "null"

Ian
 
Old 07-18-2003, 12:09 PM   #9
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Original Poster
Rep: Reputation: 46
coolness. I learn something new everyday here....Thanks..
 
Old 07-21-2003, 04:21 PM   #10
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Original Poster
Rep: Reputation: 46
Strange results

Ok. I set up the cron job to run the script below every six hours. After it failed to email me a log (or anything else) I tried to run the command from the script manually. Here is the script

#!/bin/bash
# My script to email /var/log/maillog
mail iluvspam@aol.com > /var/log/maillog
cat /dev/null/ > /var/log/maillog
# End of script

I ran the first command from a prompt and it sits there and does nothing, except it seems to be working on it. After a couple of hours it's still there chugging away. I try to Ctrl-C it, and it says

Interupt - hit Ctrl-C again to abort letter

So I do and it returns me to a prompt. My question is this. My /var/log/maillog file was 72kb long when the script was executed, so why does it take hours for the command to send the message. I may have it do it overnight to see if it ever actually sends the message. I am confused...

Last edited by Pcghost; 07-21-2003 at 04:45 PM.
 
Old 07-21-2003, 04:31 PM   #11
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
2 @ in one address?
 
Old 07-21-2003, 04:44 PM   #12
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Original Poster
Rep: Reputation: 46
sorry that was a typo. I normally use iluvspam@aol.com
 
Old 07-21-2003, 05:02 PM   #13
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Also the first > should be < since it is reading the input not providing output.
 
Old 07-21-2003, 05:54 PM   #14
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Original Poster
Rep: Reputation: 46
Thanks I will check that and see if it fixes the problem..
 
Old 07-22-2003, 11:37 AM   #15
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Original Poster
Rep: Reputation: 46
That worked! Thanks to all who helped me solve this dillema. Who would have thought that a < instead of a > could cause so much trouble? I better go brush up on my bash. :-)
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Emailing log files and system mail... AnRkey Linux - Security 6 11-10-2005 06:17 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
How to control log file size in /var/log? yan Linux - General 2 10-13-2003 05:00 PM
what log file generator that support squid log? heero82 Linux - Software 2 07-11-2003 08:52 PM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 08:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:55 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
Open Source Consulting | Domain Registration