- To: rickp@xxxxxxxxxxxxxx
- Subject: Re: [SLUG] Scripting mystery
- From: James Polley <slug@xxxxxxxxxxx>
- Date: Sun, 10 May 2009 17:50:31 +1000
- Cc: slug <slug@xxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:from:date:x-google-sender-auth:message-id:subject:to:cc :content-type; bh=ISDAuOVWOsOSk25gq+TjgOYkGYmCHCGp9FEIkdBZpUQ=; b=G1zAx8itsXuii37kfdOhBOA3u63ejLLGatvRhglaok7nFoSYOCdV5ztnkU8M1lHx40 VlUAM3cLhDX9w0CM4NACuw+W+C7pmyEc373vXL1T7iGEU32DRSIy0hmEcJJlIVxhMNBq VPKpv8qGaDNIPeZURhh0Otmj9LOiOe46M5t4c=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=CqYt+KQUF50XjZEkOmR5T6CmCSo5cBBPc7FYRtSOgoDx2Jo1V25vTtL5sP1FJuOjiM ro+7gTrOFx5xiwKtOYBPMU7vieKgV//j21zZzIipuqoAwpfw9leJu5QRRyGMVdLDIgrC Hub43rBqUSucnegfoeC0l16b3TjxEQBkYzHQw=
On Sun, May 10, 2009 at 5:42 PM, Rick Phillips <rickp@xxxxxxxxxxxxxx> wrote:
> James,
>
> > Searching for "works from command line but not via cron" shows that
> you're
> > not alone :)
> > Usually, this stems from the fact that cron doesn't execute your various
> > shell initialisation scripts - ~/.profile, ~/.bashrc, ~/.bash_profile,
> > ~/.login, etc. A common problem is thus that $PATH isn't set (when the
> > script runs under cron) to what you expect (based on what you see when
> > you're running it by hand). However, all sorts of other things could be
> > different: your ~/.bash_profile might set a non-standard umask; or set up
> > some aliases that don't exist when the script runs under cron.
> >
> Nothing non standard about my bash profile but on this system, both root
> and my own bash profiles are identical.
Sorry, my ramblings weren't very clear
The point is that cron doesn't load *anyone's* profile; it doesn't matter
what's in roots, it will never be looked at.
The usual problem is that even the standard profile includes path mappings
that the cronjob doesn't get; but you seem to have allowed for that by
explicitly defining paths.
>
>
> > Changing the shebang line to "#!/bin/sh -x" will cause each line to be
> > echoed; if you then change the cronjob to ">>/var/log/cronlog" or similar
> > you should get some more information about what cron is actually running,
> > and what the rsync commands are doing.
> >
>
> I will add the logging.
>
> > A random guesses, aside from the things I've mentioned above: the shebang
> > line stipulates /bin/sh; I'd bet you're not using /bin/sh as your shell.
> On
> > some systems /bin/sh is bash; on other systems it's something different -
> > maybe sh, maybe dash, maybe bash-in-sh-compatibility-mode.
> >
> I hoping that the shebang line is the problem although that does not
> explain why it runs on the CLI as root and not fully as root in cron. I
> have changed it to bash but won't know until tomorrow morning if it is
> going to behave.
>
> > Another random guess: if the cronjob runs as a user who doesn't have
> > 192.168.0.20 in their ~/.ssh/known_hosts file, ssh will ask questions
> about
> > whether you really want to connect. It's possible that when you do it by
> > hand you have a pre-populated ~/.ssh/known_hosts, but the cronjob runs as
> a
> > different user and doesn't have that.
> >
> No - that's not the issue. 192.168.0.20 is included in root's known
> hosts.
>
> Thanks for giving me some places to look.
>
> Rick
>
> --
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
>