Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820
Rep:
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?
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820
Original Poster
Rep:
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?
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820
Original Poster
Rep:
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?
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820
Original Poster
Rep:
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...
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820
Original Poster
Rep:
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. :-)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.