LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
Search this Thread
Old 05-15-2008, 12:50 PM   #1
NewShockerGuy
LQ Newbie
 
Registered: May 2008
Posts: 2

Rep: Reputation: 0
Arrow 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
 
Old 05-15-2008, 01:02 PM   #2
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 475

Rep: Reputation: 73
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.
 
Old 05-15-2008, 01:41 PM   #3
trashbird1240
Member
 
Registered: Sep 2006
Location: Durham, NC
Distribution: Slackware, Ubuntu (yes, both)
Posts: 463

Rep: Reputation: 31
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
 
Old 05-15-2008, 05:13 PM   #4
NewShockerGuy
LQ Newbie
 
Registered: May 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Arrow

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
 
Old 05-15-2008, 05:24 PM   #5
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 475

Rep: Reputation: 73
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)
 
Old 05-16-2008, 01:09 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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.
 
Old 05-16-2008, 07:57 AM   #7
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 475

Rep: Reputation: 73
Quote:
Originally Posted by chrism01 View Post
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.
 
Old 05-16-2008, 10:23 AM   #8
trashbird1240
Member
 
Registered: Sep 2006
Location: Durham, NC
Distribution: Slackware, Ubuntu (yes, both)
Posts: 463

Rep: Reputation: 31
Quote:
Originally Posted by NewShockerGuy View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cron job email results... ryedunn Linux - General 7 01-26-2005 11:27 PM
newbie needing help creating a cron job Lleb_KCir Linux - Software 5 12-13-2004 04:58 PM
cron job that email a text file paynsr Linux - Newbie 1 03-29-2004 02:36 PM
Cron job , send email mikeshn Linux - General 1 09-21-2003 10:02 AM
Send Email + Txt Attachment Using Cron Job beringer Linux - Newbie 3 01-31-2003 11:23 AM


All times are GMT -5. The time now is 05:24 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration