LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   I need the syntax for emailing a log file. (https://www.linuxquestions.org/questions/linux-general-1/i-need-the-syntax-for-emailing-a-log-file-46516/)

Pcghost 02-21-2003 11:09 AM

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?

Mara 02-21-2003 02:53 PM

mail someone@somewhere.org < file

Pcghost 07-18-2003 11:18 AM

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?

Mara 07-18-2003 11:21 AM

You may try to make the file empty (size: 0) and not to delete it.

Pcghost 07-18-2003 11:23 AM

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?

Blinker_Fluid 07-18-2003 11:56 AM

cat /dev/null > /var/log/whateverlogfileyouwanttoempty

Pcghost 07-18-2003 12:05 PM

Cool. Thanks Blinker_Fluid. I will give that a shot..

green_dragon37 07-18-2003 12:05 PM

In shorter form:
Code:

: > /filetoempty
The ':' in bash scripting means "null"

Ian

Pcghost 07-18-2003 12:09 PM

coolness. I learn something new everyday here....Thanks..

Pcghost 07-21-2003 04:21 PM

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...:confused: :scratch:

david_ross 07-21-2003 04:31 PM

2 @ in one address?

Pcghost 07-21-2003 04:44 PM

sorry that was a typo. I normally use iluvspam@aol.com

david_ross 07-21-2003 05:02 PM

Also the first > should be < since it is reading the input not providing output.

Pcghost 07-21-2003 05:54 PM

Thanks I will check that and see if it fixes the problem..

Pcghost 07-22-2003 11:37 AM

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. :-)


All times are GMT -5. The time now is 01:47 AM.