Hello everyone,
I'm setting up a fetchmail command to run every five minutes so I can get email from another POP3 account. The fetchmail package was installed via yum.
I can execute the command manually on the command line. But I'm having trouble when it's run from cron.
I have noticed that commands run via cron and execute via /bin/sh, so I tried to run the fetchmail command manually. This is what I get:
[root@scalix ~]# /bin/sh /usr/bin/fetchmail /usr/bin/fetchmail: /usr/bin/fetchmail: cannot execute binary file
What could be the problem here? Anyone else having problems with fetchmail?
Matt Arnilo S. Baluyos (Mailing Lists) wrote:
I have noticed that commands run via cron and execute via /bin/sh, so I tried to run the fetchmail command manually. This is what I get:
[root@scalix ~]# /bin/sh /usr/bin/fetchmail /usr/bin/fetchmail: /usr/bin/fetchmail: cannot execute binary file
What could be the problem here? Anyone else having problems with fetchmail?
Fetchmail is a binary (executable), not a shell script. So you can't run it like that.
You probably want a helper script that will execute fetchmail for you. In many cases you'll need to specify options on the command line anyway. For example, write a script called "my-fetchmail-script":
#!/bin/sh fetchmail --some-option --some-other-option
and run "my-fetchmail-script" from cron.
Tim
On 3/25/07, Tim Jackson lists@timj.co.uk wrote:
Fetchmail is a binary (executable), not a shell script. So you can't run it like that.
You probably want a helper script that will execute fetchmail for you. In many cases you'll need to specify options on the command line anyway. For example, write a script called "my-fetchmail-script":
#!/bin/sh fetchmail --some-option --some-other-option
and run "my-fetchmail-script" from cron.
Ok. That works. Thanks Tim.
Funny why cron behaves like that, does that mean I would have to make a helper script to run any other command I would want (as opposed to calling them directly)?
On Sun, Mar 25, 2007 at 06:48:13PM +0800, Matt Arnilo S. Baluyos (Mailing Lists) wrote:
I have noticed that commands run via cron and execute via /bin/sh, so I tried to run the fetchmail command manually. This is what I get:
[root@scalix ~]# /bin/sh /usr/bin/fetchmail /usr/bin/fetchmail: /usr/bin/fetchmail: cannot execute binary file
What could be the problem here? Anyone else having problems with fetchmail?
Cron doesn't run like that. Cron runs "sh -c" eg /bin/sh -c /usr/bin/fetchmail and that works just fine.
$ cat /etc/redhat-release CentOS release 4.4 (Final) $ uname -sr Linux 2.6.9-42.0.10.EL $ /bin/sh -c /usr/bin/fetchmail fetchmail: no mailservers have been specified.
On Sun, 2007-03-25 at 18:48 +0800, Matt Arnilo S. Baluyos (Mailing Lists) wrote:
Hello everyone,
I'm setting up a fetchmail command to run every five minutes so I can get email from another POP3 account. The fetchmail package was installed via yum.
I can execute the command manually on the command line. But I'm having trouble when it's run from cron.
I have noticed that commands run via cron and execute via /bin/sh, so I tried to run the fetchmail command manually. This is what I get:
[root@scalix ~]# /bin/sh /usr/bin/fetchmail /usr/bin/fetchmail: /usr/bin/fetchmail: cannot execute binary file
What could be the problem here? Anyone else having problems with fetchmail?
Going from memory, so I hope this is not too erroneous.
As you may have deduced from the other replies, you don't *need* "/bin/bash" at the start of the command line when executing a typical binary.
Even for cron entries.
The linker/loader has some logic to automatically handle various binary formats. In fact, AFAIR, the convention of the first line in a shell script having something like "#!/bin/bash" was to allow this same "automatic" loading to occur. I've never followed up to see if any OS implementation actually handles it correctly. I presume that a program would call the loader and pass the file name to get it to work, if it does indeed work.
Further, I believe that normal shell scripts don't need the leading "/bin/sh" (or similar) either. As another respondent pointed out, the default is to execute via "/bin/sh -c ...." or similar. For binaries, this does interject a small amount of additional overhead. It is not significant.
One point of significance: the environmental variables that exist at command line do/may not be set/correct when crontab invokes a process. For this reason, some binaries may need a "wrapper" script that is called by cron. It may be as simple as #!/bin/bash --login... some more stuff" or even just contain "." (or "source", if you prefer) command to read the appropriate .bashrc or .bash_profile to inject needed variables into the environment.
HTH -- Bill
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Sun, Mar 25, 2007 at 06:48:13PM +0800, Matt Arnilo S. Baluyos (Mailing Lists) wrote:
Hello everyone,
I'm setting up a fetchmail command to run every five minutes so I can get email from another POP3 account. The fetchmail package was installed via yum.
Why not run fetchmail in daemon mode ?
fetchmail -d300 --syslog
That would fetch messages each 5 minutes.
- -- Rodrigo Barbosa "Quid quid Latine dictum sit, altum viditur" "Be excellent to each other ..." - Bill & Ted (Wyld Stallyns)
On 3/26/07, Rodrigo Barbosa rodrigob@darkover.org wrote:
Why not run fetchmail in daemon mode ?
fetchmail -d300 --syslog
That would fetch messages each 5 minutes.
Cool. I didn't know fetchmail had this switch.
Thanks. I'll look more into this.