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?
|
mail someone@somewhere.org < file
|
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?
|
You may try to make the file empty (size: 0) and not to delete it.
|
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?
|
cat /dev/null > /var/log/whateverlogfileyouwanttoempty
|
Cool. Thanks Blinker_Fluid. I will give that a shot..
|
In shorter form:
Code:
: > /filetoempty Ian |
coolness. I learn something new everyday here....Thanks..
|
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: |
2 @ in one address?
|
sorry that was a typo. I normally use iluvspam@aol.com
|
Also the first > should be < since it is reading the input not providing output.
|
Thanks I will check that and see if it fixes the problem..
|
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. |