LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-26-2006, 09:20 AM   #1
dansawyer
Member
 
Registered: Mar 2005
Posts: 124

Rep: Reputation: 15
question about a cron script


All,

Below are cron scripts. These do not run. Cron logs shows it is activated. fetchmail.cron is in /etc/cron.hourly and if 'run-parts /etc/cron.hourly' is run the scripts run. Also scripts in cron.daily appear to run.

Thanks - Dan

cat of crontab:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
05 * * * * root /etc/cron.hourly/fetchmail.cron
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

cat of fetchmail.cron
#!/bin/bash
/usr/bin/fetchmail
 
Old 12-26-2006, 09:54 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
What distribution are you running?

run-parts is a script that will run other programs in a single directory. Your fetchmail.cron script should run twice. Via run-parts and your second entry "05 * * * * root /etc/cron.hourly/fetchmail.cron".

Are there any scripts in /etc/cron.weekly or /etc/cron.monthly directories? If not then there is nothing to run.

http://nixdoc.net/man-pages/Linux/man8/run-parts.8.html

Last edited by michaelk; 12-26-2006 at 09:55 AM.
 
Old 12-26-2006, 11:59 AM   #3
dansawyer
Member
 
Registered: Mar 2005
Posts: 124

Original Poster
Rep: Reputation: 15
Thanks,

Yes, it should run twice. It does not run at all. When this gets debugged one will be removed.

The release is fc6. There are scripts in cron.daily and cron.weekly. They are running.

/etc/cron.hourly/fetchmail.cron runs the script.
run-parts /etc/cron.hourly/ also runs the script.

- Dan
 
Old 12-26-2006, 01:21 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
What are the permission of your fetchmail script?
Is it executable?
 
Old 12-26-2006, 02:32 PM   #5
dansawyer
Member
 
Registered: Mar 2005
Posts: 124

Original Poster
Rep: Reputation: 15
permissions are ok, the script runs from

ls -altr /etc/cron.hourly/
total 32
drwxr-xr-x 2 root root 4096 Jul 14 21:05 .
drwxr-xr-x 101 root root 12288 Dec 24 04:03 ..
-rwxr-xr-x 1 root root 32 Dec 25 19:44 fetchmail.cron
 
Old 12-26-2006, 03:52 PM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
Fetchmail runs as a daemon - ie it can stay running once started so why not use that feature and put a mail-checking frequency in your .fetchtmailrc rather than using cron?

E.g. i use

set daemon 300

to make it check mail every 5 minutes

Last edited by dive; 12-26-2006 at 03:56 PM.
 
Old 12-27-2006, 10:50 AM   #7
dansawyer
Member
 
Registered: Mar 2005
Posts: 124

Original Poster
Rep: Reputation: 15
Thanks for the suggestion, however the script is still not working. Is there a way to create a detailed log? Cron log simply shows the script as being run. There is no error.

Dan
 
Old 12-27-2006, 11:53 AM   #8
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
You could change the line in the script to:

/usr/bin/fetchmail 1>>fetch.log 2>&1

This would output any messages into a log and you can see if there are any errors.

Last edited by dive; 12-27-2006 at 12:00 PM.
 
Old 12-27-2006, 08:49 PM   #9
dansawyer
Member
 
Registered: Mar 2005
Posts: 124

Original Poster
Rep: Reputation: 15
Thanks for that tip. The output of the above is:

fetchmail: WARNING: Running as root is discouraged.
fetchmail: can't find a password for root@1.
fetchmail: WARNING: Running as root is discouraged.
fetchmail: can't find a password for root@1.
fetchmail: WARNING: Running as root is discouraged.
fetchmail: can't find a password for root@1.

Where does the password come from? The script runs when called from a bash shell. It gets the above error from cron. Is there a password associated with cron?

Thanks - Dan
 
Old 12-27-2006, 09:02 PM   #10
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
The password seems to be the email login pass for root@1 which it thinks is the pop3 account to check. There are a few problems running programs with cron that use environmental variables. Usually you need to specify env vars in your script.

Does the script run normal from a bash shell while logged in as as root? Maybe check roots .fetchmailrc? Or maybe you need to copy .fetchmailrc to /etc/fetchmailrc to make it global.

I have always run fetchmail from my user account, I would suggest doing that and using the daemon feature though.

Last edited by dive; 12-27-2006 at 09:05 PM.
 
Old 12-28-2006, 09:28 AM   #11
dansawyer
Member
 
Registered: Mar 2005
Posts: 124

Original Poster
Rep: Reputation: 15
Thanks. The script has been moved from 'root' to another account. (the script was developed several years ago and not changed.)

The root@1 error resulted from the script call line that directed normal and error output to a file. That has been remove.

All the permissions have been updated. The script runs as: /home/../script. /etc/crontab has been changed to run as: account /home/../script.

Now we shall see. Thanks - Dan
 
Old 12-28-2006, 02:19 PM   #12
dansawyer
Member
 
Registered: Mar 2005
Posts: 124

Original Poster
Rep: Reputation: 15
This did not create a change. Below is the updated crontab. The scripts in cron.daily run. The script runs successfully as user 'buffer' with /home/buffer/fetchmail.cron

There does not seem to be anything missing.


SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
05 * * * * buffer /home/buffer/fetchmail.cron
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

/etc/cron.daily:
total 124
drwxr-xr-x 2 root root 4096 Dec 26 13:41 .
drwxr-xr-x 102 root root 12288 Dec 27 04:22 ..
-rwxr-xr-x 1 root root 133 Jul 12 19:18 00webalizer
-rwxr-xr-x 1 root root 379 Oct 29 23:37 0anacron
lrwxrwxrwx 1 root root 39 Dec 26 13:37 0logwatch -> /usr/share/logwatch/scripts/logwatch.pl
-rwxr-xr-x 1 root root 2936 Nov 28 05:16 beagle-crawl-system
-rwxr-xr-x 1 root root 1042 Aug 17 08:22 certwatch
-rwxr-xr-x 1 root root 118 Nov 22 04:18 cups
-rwxr-xr-x 1 root root 180 Oct 1 13:26 logrotate
-rwxr-xr-x 1 dan dan 222 Dec 23 14:15 mailscript.cron
-rwxr-xr-x 1 root root 418 Jul 12 22:09 makewhatis.cron
-rwxr-xr-x 1 root root 137 Nov 26 04:04 mlocate.cron
-rwxr-xr-x 1 root root 2181 Jun 21 2006 prelink
-rwxr-xr-x 1 root root 114 Sep 7 04:05 rpm
-rwxr-xr-x 1 root root 290 Jul 12 18:23 tmpwatch

/etc/cron.hourly:
total 32
drwxr-xr-x 2 root root 4096 Jul 14 21:05 .
drwxr-xr-x 102 root root 12288 Dec 27 04:22 ..
-rwxr-xr-x 1 buffer buffer 64 Dec 28 06:48 fetchmail.cron

cat fetchmail.cron
#!/bin/bash
/usr/bin/fetchmail
[dan@server buffer]$ ls -al fetchmail.cron
-rwxr-xr-x 1 buffer buffer 32 Dec 28 12:01 fetchmail.cron
 
Old 12-28-2006, 03:58 PM   #13
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
What does buffer's .fetchmailrc look like (without passwords of course)

Does putting 'export HOME=/home/buffer' in the rc file do any good?
 
Old 12-28-2006, 09:39 PM   #14
dansawyer
Member
 
Registered: Mar 2005
Posts: 124

Original Poster
Rep: Reputation: 15
Here it is. The script runs. I may try putting it in the daily. There is a script there that runs.

cat .fetchmailrc
defaults proto pop3
poll mail.xxx.com:
user dansawyer, fetchall, password xxxx is buffer here;
poll server.sawyer.home proto auto:
user buffer, keep, fetchall, password xxxxx, is dansawyer here;
poll server.sawyer.home proto auto:
user buffer, keep, fetchall, password xxxxx, is test here;
poll server.sawyer.home proto auto:
user buffer, keep, fetchall, password xxxxx, is netscape here;
poll server.sawyer.home proto auto:
user buffer, keep, fetchall, password xxxxx, is dan here;
poll server.sawyer.home proto auto:
user buffer, keep, fetchall, password xxxxx, is portable here;
poll server.sawyer.home proto auto:
user buffer, fetchall, password xxxxx, is laura here;
 
Old 12-29-2006, 10:25 AM   #15
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
Did you try putting

export HOME=/home/buffer

in your fetchmail.cron?
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
MySQL shell usage question / cron script Seventh Programming 2 01-13-2006 01:34 PM
PPPD Script problem when cron-scheduling the script andresurzagasti Linux - Networking 0 11-24-2004 02:54 PM
Cron script help mpls mikeg Linux - Software 2 09-24-2004 09:28 AM
Help with Script and Cron goldstonrumpke Linux - Newbie 10 05-30-2004 11:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration