1819814 Members
2735 Online
109607 Solutions
New Discussion юеВ

cron and email???

 
Sandy_11
Occasional Contributor

cron and email???

we are using mandrake and we want to use cron to generate the task of sending email automatically.
But we have tried many times, and still there is no response.
We also test it just simply write out a command to copy file at a definite time, but also no repsonse.
So are there any problems or do we miss any procedures???

Thanks a lot
10 REPLIES 10
Justo Exposito
Esteemed Contributor

Re: cron and email???

Hi,

Can you put your crontab file here?

Do you try to email from the command line?

Can you put your script here?

Regards,

Justo.
Help is a Beatiful word
Sandy_11
Occasional Contributor

Re: cron and email???

but before we use cron to test the email, we just simply want to copy the file from one particular file e.g. file.txt to backup.txt,
but it also not function. maybe I now attach the file, so can u please help me to take a look, to see whether it has problem??


here are the steps we have done:
1. create a txt file called "file.txt"
2. create a crontab file called "mycronfile" and the command line inside the file is "7 18 25 4 4 cp ../usr/test/file.txt ../usr/test/backup.txt
"
3. put "mycronfile" to the folder ./etc/cron.d
4. In Konsole typed "crontab mycronfile"
5. But no backup.txt is created

really thanks a lot.
Nico van Royen
Frequent Advisor

Re: cron and email???

I see that you have the command like "../usr/" ..

Try removing the .. (dot dot) in front of the /usr. (since /usr/ is already an absolute path....

- Nico
If all else fails, try reading the manual...
Sandy_11
Occasional Contributor

Re: cron and email???

but we have tried to delete the .. before, but it still not function??
Nico van Royen
Frequent Advisor

Re: cron and email???

If its only for testing if cron sends out email, then try the following:

Make a small shell script with something like:

user@system$ vi /tmp/test.sh
#!/bin/bash
echo "`date`"
echo " -- Testing cron -> mail "

(make sure to set the scipt with permissions set to execute,

user@system$ chmod 755 /tmp/test.sh

Place it in the crontab with
user@system$ crontab -e

0 * * * * /tmp/test.sh

this will execute the script every hour, remove the entry again when succesfull.

The small "script" will mail the output of test.sh to that user.

- Nico
If all else fails, try reading the manual...
Justo Exposito
Esteemed Contributor

Re: cron and email???

Hi Sandy,

Sorry for the delay, I think that your problem is that you put a relative path in your crontab for the copy.

Try to put the absolute path in your cp command.

Something like that:
7 18 25 4 4 cp /usr/test/file.txt /usr/test/backup.txt

and other thing, you must edit your crontab file with the crontab -e command, if not you must reinitilize the cron daemon after you made the change.

Hope this help,

Justo.
Help is a Beatiful word
Sandy_11
Occasional Contributor

Re: cron and email???

first,thanks a lot for all reply~~

but i have tried this, seems still not function. and I would like to ask how to check that the command has been executived. As you mention, you say that a mail will be sent out??? but where to receive that email ???

really thanks a lot
Mark Fenton
Esteemed Contributor

Re: cron and email???

Sandy,

I'm not certain that Mandrake's implementation of cron suffers the same restrictions, but there is a limit on the number of parameters that you feed a crontab entry, and on my system, that number is apparently 1.

So...

Put your commands into a script, and run the script from cron.

As to where to send the email output -- that depends entirely on your setup. Typically, the owner of the cron job would receive any email output. This can be aliased in your mail program's aliases file to go anywhere you like.

hth
Mark
Jeffrey Wong
Advisor

Re: cron and email???

A couple of things here. First if you are trying to add a cron job by adding a file to /etc/cron.d I'm pretty sure that you have to restart crond. Try running "/etc/rc.d/init.d/crond restart". Since you did not specify a user to run as, the job will run as root and any output will be mailed to root. Also, as several other people have pointed out cron jobs should always use absolute paths.
CJ Hoeschen
New Member

Re: cron and email???

I have used Mandrake with a cron job before. Here is what I have done:

Created a file in the users home folder, in my case it was root.

In this file put in your cron commands
0 19 * * 1 /root/scripts/monday.pl
This command will run our monday backup script at 7:00

Save the file and then run crontab. In my case I saved it as /root/scripts/cronjobs so I would type in crontab /root/script/cronjobs. To verify if it is in place run crontab -l to list your cronjobs for that user.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." -- Albert Einstein