Creating a cron job to email me a txt file/format?
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.
Creating a cron job to email me a txt file/format?
I'm new to Cron Jobs... but I would like to try something to make it a little easier on myself here at work.
I have a template that I use that's in txt /text file. It looks like this:
Backup Group name1 via Legato:
-
Backup Group name2 via Legato:
-
Backup Group name3 via Legato:
-
etc..
It is only 15 groups so it's not a big file persay just long. I check the status of my backups and then log it as successful or not... 99% they are.
I would like to create a cron job so that it has this template in it and can simply email me everyday M-F this template so that way I can just fill it in, save it and be done.
The program to send yourself (or anyone else) mail from stdout is called "mail" although that's really an alias for mailx on my system. Any cron job not directed to /dev/null should send you a mail automatically. If you want to limit your output, you can put the mail pipe in the script you're running:
Code:
#!/bin/sh
rsync --delete -tavz this_file /mnt/hd/ |mail steve
Will send a mail to steve with the output from rsync (btw rsync is awesome).
if it is to be run as a particular user (yourself) then use the command crontab -e (to edit your crontab) and add the example i provided (or whatever works for you based on your review of the manual page).
this places it in /var/spool/cron/<your-user> (for example)
if you want it to run from "the system" (as root from one of the /etc/cron.* directories) it is similar in syntax but you can consult the other cron-jobs in the /etc/cron.* directories for examples.
I suggest using a non-root user if it is not something that needs root privileges to perform (and this doesn't sound like it does)
I have never written a script before sooo... I don't know how to do that.
So learn how to do it.
Here's a Quick Synopsis: Open a text editor (man vi; man emacs). Enter the text. Save the file. Change the permissions (man chmod) to executable. Enter the script's name on the command line.
I'm bein' real with you man: it's not hard. Getting over that self-defeating belief is the biggest step toward computing empowerment.
Quote:
I have heard or RSYNC but never used it so I have no clue how it even works... :-(
So learn about it. man rsync tells you everything you need to know.
Quote:
This is a silly question but where do I put the cron job or how do I start it?
Cron starts it for you, that's the whole idea.
Quote:
Is the path that I must take for the cron job /dev/null
/dev/null is the "bit bucket" --- you direct output there if you want it to disappear:
Code:
echo "beer beer beer cheese" >> /dev/null
Quote:
Still trying to learn as much as possible about linux :-)
Good! I suggest a structured approach, such as reading a detailed book on the subject. My favorite is Running Linux.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.