LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Creating a cron job to email me a txt file/format? (https://www.linuxquestions.org/questions/linux-general-1/creating-a-cron-job-to-email-me-a-txt-file-format-642422/)

NewShockerGuy 05-15-2008 11:50 AM

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.

I am currently running Fedora 7 on my pc.

Thanks for the help in advance,
-Nigel

rayfordj 05-15-2008 12:02 PM

maybe something like this (or a script that cron uses and then you do the "legwork" in the script)
Code:

0 8 * * 1-5 cat /path/to/template.txt | mail -s "Backup Template" nigel@example.com
this should send the txt file to you with the subject of 'backup template' every day at 8:00am Mon-Fri. see man 5 crontab for more information.

Hope this helps.

trashbird1240 05-15-2008 12:41 PM

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

Joel

NewShockerGuy 05-15-2008 04:13 PM

Thanks guys.

I have never written a script before sooo... I don't know how to do that.

I have heard or RSYNC but never used it so I have no clue how it even works... :-(


This is a silly question but where do I put the cron job or how do I start it?

Is the path that I must take for the cron job /dev/null

?

Still trying to learn as much as possible about linux :-)

Thanks again,
-Nigel

rayfordj 05-15-2008 04:24 PM

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)

chrism01 05-16-2008 12:09 AM

Nice desc/tutorial about cron: http://www.adminschoice.com/docs/cro...Crontab%20file
BTW, always use the full/absolute paths to all cmds you use in a cron script, as the cron env is extremely minimal.

rayfordj 05-16-2008 06:57 AM

Quote:

Originally Posted by chrism01 (Post 3154858)
BTW, always use the full/absolute paths to all cmds you use in a cron script, as the cron env is extremely minimal.

agreed 100%. my crontab does. in my haste to post i forgot my better practices...

definetely a good practice to use absolute path as chrism01 noted.

trashbird1240 05-16-2008 09:23 AM

Quote:

Originally Posted by NewShockerGuy (Post 3154513)
Thanks guys.

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.


All times are GMT -5. The time now is 11:45 PM.