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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-15-2008, 11:50 AM
|
#1
|
|
LQ Newbie
Registered: May 2008
Posts: 2
Rep:
|
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
|
|
|
|
05-15-2008, 12:02 PM
|
#2
|
|
Member
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 472
Rep:
|
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.
|
|
|
|
05-15-2008, 12:41 PM
|
#3
|
|
Member
Registered: Sep 2006
Location: Durham, NC
Distribution: Slackware, Ubuntu (yes, both)
Posts: 463
Rep:
|
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
|
|
|
|
05-15-2008, 04:13 PM
|
#4
|
|
LQ Newbie
Registered: May 2008
Posts: 2
Original Poster
Rep:
|
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
|
|
|
|
05-15-2008, 04:24 PM
|
#5
|
|
Member
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 472
Rep:
|
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)
|
|
|
|
05-16-2008, 12:09 AM
|
#6
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 15,000
|
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.
|
|
|
|
05-16-2008, 06:57 AM
|
#7
|
|
Member
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 472
Rep:
|
Quote:
Originally Posted by chrism01
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.
|
|
|
|
05-16-2008, 09:23 AM
|
#8
|
|
Member
Registered: Sep 2006
Location: Durham, NC
Distribution: Slackware, Ubuntu (yes, both)
Posts: 463
Rep:
|
Quote:
Originally Posted by NewShockerGuy
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:52 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|