1828491 Members
2238 Online
109978 Solutions
New Discussion

Asking about CRON

 
SOLVED
Go to solution
Chan Choth PUTH
Advisor

Asking about CRON

Dear Sir,

I used SUSE Linux 7.1. I would like to
use crontab to let it running my shell script but it is not working and I do not know why? Would you to help me resolving this problem? Thank you so much for your assistance. I write my script like the following:

My test number 1:
Very simple testing script:
$ vi /root/test.sh
#!/bin/sh
echo "How are you?"
$ chmod +x /root/test.sh
$ crontab -e
* * * * * root /root/test.sh
$ /etc/rc.d/cron restart

My test number 2:
Very simple testing script:
$ vi /root/test1.sh
#!/bin/sh
echo "Thank you so much for your assistance."
$ chmod +x /root/test1.sh
$ crontab -e
* * * * * root /root/test1.sh
$ /etc/rc.d/cron restart

My test number 3:
Very simple testing script:
$ vi /root/test2.sh
#!/bin/sh
echo "Thank you so much for your assistance."
$ chmod +x /root/test2.sh
$ vi /etc/crontab
* * * * * root /root/test2.sh
$ /etc/rc.d/cron restart

My test number 4:
Very simple testing script:
$ vi /root/test3.sh
#!/bin/sh
echo "Thank you so much for your assistance."
$ chmod +x /root/test3.sh
$ vi /etc/crontab
* * * * * /bin/sh /root/test3.sh
$ /etc/rc.d/cron restart

But I have never got the message that I want it to display every minutes by using cron and I really hope that I will receive your assistance and I would like to deeply thank you so much for your help.

Regards,

Choth
Sharing IT knowledge and Information
22 REPLIES 22
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

Hi,
I think that script is executing But the problem is with echo , because it does not have current terminal to echo as it is run by
cron . To test do this

$ vi /root/test.sh
#!/bin/sh
echo "How are you?" > /tmp/test.cron
$ chmod +x /root/test.sh
$ crontab -e
* * * * * root /root/test.sh
$ /etc/rc.d/cron restart

Now after that time of execution of the script
look at this file /tmp/test.cron , does have
this line .How are you?. That means you cron
job has suceeded.

Also look at this file for any errors.
/var/log/cron

regards,
U.SivaKumar



Innovations are made when conventions are broken
Stuart Browne
Honored Contributor

Re: Asking about CRON

All-over issues:

You don't need to restart cron. Period.

Test number 1 problem:

for the 'user' crontab's, you do not require a username. just:

* * * * * /root/test.sh

would suffice.

Test number 2 problem:

Same as above.

Test number 3:

Actually, that should have worked. Where does root's mail get forwareded too?

Test number 4 problem: This wouldn't work. The /etc/crontab requries a 'username' to run the script as.


General rule:

crontab -e

user cront-tab. Requries 5 time fields, and the program to run. Unless otherwise specified (by re-declaring the environment variable MAILTO), all tty output will go to the user's who's crontab it is.

/etc/crontab

System crontabs. Requires 5 time fields, a user field, and the program to run. Mail will go to 'root' unless otherwise specified.

Dumb question: does /bin/sh exist, and is it executeable? :) Try leaving it out. All cron routines are run using the standard shell anyway (so just putting the echo in should work).

Another thing to try, avoiding the mail subsystems, is to try outputting the information to a file instead of to STDOUT.

echo "[`date`] Thank you so much for your assistance." > /tmp/some.file

Check /tmp/some.file for updates..


Last resort:

Using the time '* * * * *' should work (execute routine every minute, on the minute), but it's possible that the version of cron you are using (not sure if it's Vixie or not) does not allow it. try setting it up to run every two minutes ('*/2 * * * *') or at a specified minute of the day.


Anyway, some things to try. Hopefully this will help you.
One long-haired git at your service...
Chan Choth PUTH
Advisor

Re: Asking about CRON

Dear Sir,

Thank you so much for your reply. I will give you my full script like the following:

$ vi /root/dns.sh

#!/bin/sh
if [ -n "`/sbin/pidof named`" ]; then
echo "`date` our DNS is fine :-)" > /var/log/dnsok.log
(
echo "From: choth "
echo "To: choth "
echo "Subject: DNS OK :-)"
echo ""
cat /var/log/dnsok.log
) | sendmail -fchoth@of.forum.org.kh choth@of.forum.org.kh
exit 0
else
echo "Our DNS is down on `date`" >> /var/log/dns.log
echo "Our DNS is down on `date`" > /var/log/dnserror.log
/etc/init.d/named start
for ((i=0;i<=3;i++))
do
if [ -n "`/sbin/pidof named`" ]; then
exit 0
else
/etc/init.d/named start
fi
done
(
echo "From: choth "
echo "Subject: DNS Status"
echo "To: choth "
echo ""
cat /var/log/dnserror.log
) | sendmail -fchoth@of.forum.org.kh choth@of.forum.org.kh
fi

$ chmod +x /root/dns.sh
and then I fire the command crontab -e
* * * * * /bin/sh /root/dns.sh

The thing that I say it is not running because it does not mail to me . When the DNS is up I can see the log file /var/log/dnsok.log but why it is not mail to me? Would you mind to help me sir? What is the problem with my script? Thank you so much for your assistance.

Regards,

Chot
Sharing IT knowledge and Information
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

Hi,
Simply execute /root/dns.sh
#/root/dns.sh
Does it send the mail ??.
If not use shell debugging.
vi /root/dns.sh
remove this line
#!/bin/sh
Now
#sh -x /root/dns.sh
see any errors coming ?

Think of using mail command instead of sendmail
like this

Instead of this
(
echo "From: choth "
echo "Subject: DNS Status"
echo "To: choth "
echo ""
cat /var/log/dnserror.log
) | sendmail -fchoth@of.forum.org.kh choth@of.forum.org.kh
fi


This seems simple
(
mail -s DNS status choth@of.forum.org.kh < /var/log/dnserror.log
)
fi

regards,
U.SivaKumar






Innovations are made when conventions are broken
Chan Choth PUTH
Advisor

Re: Asking about CRON

Dear Sir,

Thank you so much for your very useful information. I would like to ask you the last question:
every two minutes is */2 what about every 3 minutes is it */3, ... every n minutes */n? Is it correct or not? Thank you so much and I am looking forward to hearing from you.

Regards,

Choth
Sharing IT knowledge and Information
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

hi,
Each entry in a crontab file consists of six fields, specifying in the following order:

minute(s) hour(s) day(s) month(s) weekday(s) command(s)
The fields are separated by spaces or tabs. The first five are integer patterns and the sixth is the command to execute. The following table briefly describes each of the fields:

Field Value Description
minute 0-59 The exact minute that the command sequence executes
hour 0-23 The hour of the day that the command sequence executes
day 1-31 The day of the month that the command sequence executes
month 1-12 The month of the year that the command sequence executes
weekday 0-6 The day of the week that the command sequence executes (Sunday = 0, Monday = 1, Tuesday = 2, and so forth)
command Special The complete sequence of commands to execute. The command string must conform to Bourne shell syntax. Commands, executables (such as scripts), or combinations are acceptable.

Each of the patterns from the first five fields may be either * (an asterisk), meaning all legal values, or a list of elements separated by commas. An element is either a number or an inclusive range, indicated by two numbers separated by a minus sign (e.g., 10-12). You can specify days with two fields: day of the month and day of the week. If you specify both of them as a list of elements, cron will observe both of them, for example:

0 0 1,15 * 1 /mydir/myprogram

The cron daemon would run the program myprogram in the mydir directory on the first and fifteenth of each month, as well as on every Monday. To specify days by only one field, the other field should be set to * , for example:

0 0 * * 1 /mydir/myprogram

In the above example, the program would run only on Mondays.

regards,
U.SivaKumar


Innovations are made when conventions are broken
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

Hi choth,
You have started many question threads, till
now you have not assigned any points to anyone.

Assigning points is recognising and encouraging people who helps you.

regards,
U.SivaKumar

Innovations are made when conventions are broken
Chan Choth PUTH
Advisor

Re: Asking about CRON

Dear Sir,

Thank you so much for your reply. I know that it has 6 fields but all I would like to ask you just only one field "minutes". I saw it from another expert that answer to me with this question saying that */2 is for every two minutes. And then for this time I would like to ask you that (just in the minute field) */2 is for every 2 minutes, but what about every 3 minutes is it */3, ... and n minutes is it */n? Thank you so much for your answer.

Regards,

Choth
Sharing IT knowledge and Information
U.SivaKumar_2
Honored Contributor
Solution

Re: Asking about CRON

Hi choth,
you are right. */3 in the minutes field will cause the cron to run the script every 3 minute.

regards,
U.SivaKumar
Innovations are made when conventions are broken
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

hi choth ,
What happened to you sendmail problem ? . solved ?.

regards,
U.SivaKumar
Innovations are made when conventions are broken
Chan Choth PUTH
Advisor

Re: Asking about CRON

Dear Sir,

Thank you so much for asking me about sendmail. I have not solved this problem yet and I also wrote a letter to yahoo in order to ask that problem "E=\r\n" but I did not get the answer from them yet. I have a returned mail like this and I would like you to explain me line by line because I would like to deeply know and I also would like to solve this problem. The error is like the following:
----- The following addresses had permanent fatal errors -----

(reason: 554 Transaction failed)
----- Transcript of session follows -----
451 4.4.1 ... reply: read error from mx1.hotmail.com.
... while talking to mx5.hotmail.com.:
>>> DATA
<<< 554 Transaction failed
554 5.0.0 ... Service unavailable
============================================
Reporting-MTA: dns; mailgw.forum.org.kh
Received-From-MTA: DNS; ofix.forum.org.kh
Arrival-Date: Wed, 18 Sep 2002 11:20:38 GMT
Final-Recipient: RFC822; khmfx@hotmail.com
Action: failed
Status: 5.0.0
Remote-MTA: DNS; mx5.hotmail.com
Diagnostic-Code: SMTP; 554 Transaction failed
Last-Attempt-Date: Wed, 18 Sep 2002 11:47:56 GMT
=====================================================
Reporting-MTA: dns; mailgw.forum.org.kh
Received-From-MTA: DNS; ofix.forum.org.kh
Arrival-Date: Wed, 18 Sep 2002 11:20:38 GMT
Final-Recipient: RFC822; khmfx@hotmail.com
Action: failed
Status: 5.0.0
Remote-MTA: DNS; mx5.hotmail.com
Diagnostic-Code: SMTP; 554 Transaction failed
Last-Attempt-Date: Wed, 18 Sep 2002 11:47:56 GMT

Finally, I would like to deeply thank you so much for your help.

Best regards,

Choth
Sharing IT knowledge and Information
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

Hi,
Refered:
Q3.10 -- How do I solve "collect: I/O error on connection" or "reply: read error from host.name" errors?
If you are just getting occasional such messages, they're probably due to a temporary network problem, or the remote host crashing or otherwise abruptly terminating the connection. If you are getting a lot of these from a single host, there is probably some incompatibility between 8.x and that host (see Q3.12 and Q3.20). If you get a lot of them in general, you may have network problems that are causing connections to get reset.

Note that this problem is sometimes caused by incompatible values of the MTU (Maximum Transmission Unit) size on a SLIP or PPP connection. Be sure that your MTU size is configured to be the same value as what your ISP has configured for your connection. If you are still having problems, then have your ISP configure your MTU size for 1500 (the maximum value), and you configure your MTU size similarly.

Another possibility is that you have a router/firewall filtering out all incoming ICMP messages, while your OS is doing "Path MTU discovery" (e.g. modern versions of Solaris do this by default). Path MTU discovery relies on certain ICMP messages being allowed through back to the host originating the traffic - see RFC 1191 for the details.

regards,
U.SivaKumar
Innovations are made when conventions are broken
Chan Choth PUTH
Advisor

Re: Asking about CRON

Dear Sir,
You said that "Another possibility is that you have a router/firewall filtering out all incoming ICMP messages, while your OS is doing "Path MTU discovery" (e.g. modern versions of Solaris do this by default). Path MTU discovery relies on certain ICMP messages being allowed through back to the host originating the traffic- see RFC 1191 for the details". I agree with you at this point. My server uses Wireless Broadband Access and CISCO router and then my users use dailup connection to connect to my server, I think that maybe it is related to the MTU that why I have got these errors. But how can I know about the MTU and how can I do it, would you mind explaining me about this issue? I use Wireless Broadband Access 64Mbps that means the speed of my connection to the Internet is 64Mbps. Thank you so much for your assistance.

Best regards,

Chot
Sharing IT knowledge and Information
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

Hi choth,

Do this in linux.
to turn off path MTU discovery
echo 1 >/proc/sys/net/ipv4/ip_no_pmtu_disc

regards,
U.SivaKumar
Innovations are made when conventions are broken
Chan Choth PUTH
Advisor

Re: Asking about CRON

Dear Sir,

Thank you so much for your assistance. To turn off path MTU discovery echo 1 >/proc/sys/net/ipv4/ip_no_pmtu_disc
What about turning on the path MTU, is it
echo 0 > /proc/sys/net/ipv4/ip_no_pmtu_disc?

Regards,

Choth
Sharing IT knowledge and Information
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

Hi,
you are right.

echo 1 - disable
echo 0 - enable

To keep the setting even after rebooting the
system. please do this.
Alternatively add the following line to /etc/sysctl.config and then run sysctl -p. This will ensure that this option is set on reboot.

net.ipv4.ip_no_pmtu_disc=1



regards,
U.SivaKumar



Innovations are made when conventions are broken
Chan Choth PUTH
Advisor

Re: Asking about CRON

Dear Sir,

I have already fired the command:
$ echo 1 > /proc/sys/net/ipv4/ip_no_pmtu_disc
And then I will see how it works and I will tell you tomorrow. I see in /etc/sendmail.cf file and I configure like this:
O PostMasterCopy=choth@of.forum.org.kh,porheng@of.forum.org.kh
I would like all the mails or errors ..etc... that mails to postmaster go to choth@of.forum.org.kh and porheng@forum.org.kh. Am I right or wrong with this configuration? One more think I receive the "E=\r\n" from Yahoo again and I do not why? Would you mind recommended me what should I do to solve this problem? Thank you so much for your assistance and I am looking forward to hearing from you.

Regards,

Chot
Sharing IT knowledge and Information
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

Hi,
PostMasterCopy option will send a copy of error
mails and other notification messages to forwarded to the specified email address.
choth@of.forum.org.kh
It is a good option to use and you are right.
I think you can try deleting E=/r/n in sendmail.cf and see that makes any difference.

Get back with results (with path MTU
disbled).

regards,

U.SivaKumar

Innovations are made when conventions are broken
Chan Choth PUTH
Advisor

Re: Asking about CRON

 
Sharing IT knowledge and Information
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

Hi,
The file types under mail queue directory of sendmail are as follows

/var/spool/mqueue/qf*
Control (queue) files for messages.

/var/spool/mqueue/df*
Data files.

/var/spool/mqueue/tf*
Temporary versions of the qf files, used during queue file rebuild.

/var/spool/mqueue/xf*
A transcript of the current session.


Since disabling PMTU has not helped you , I would suggest you upgrade your ISP line speed .
The bandwidth bottleneck also causes I/O errors

regards,
U.SivaKumar


Innovations are made when conventions are broken
Chan Choth PUTH
Advisor

Re: Asking about CRON

Dear Sir,

What are the differences between:
Control (queue) files for messages, Data files, Temporary versions of the qf files, A transcript of the current session? What do they do?

Regards,
Choth
Sharing IT knowledge and Information
U.SivaKumar_2
Honored Contributor

Re: Asking about CRON

Hi,

var/spool/mqueue/qf*
these files contains headers like sender address , recipient address , mail priority ,
of the mails in the queue.

/var/spool/mqueue/df*
These files contains the body ( data ) of the mails which are in queue.

/var/spool/mqueue/tf*
These files are actually copies of qf* files created by sendmail for modification of paramters like priority . After modification these files are copied back to qf* files. This
method prevents any possible corruption of qf* files

/var/spool/mqueue/xf*
transcript files contain error messages ( if any ) returned by various mail agents .


regards,
U.SivaKumar




Control (queue) files for messages, Data files, Temporary versions of the qf files, A transcript of the current session? What do they do?

Innovations are made when conventions are broken