FW: Can cron run ssh commands?
Harig, Mark A.
maharig@idirect.net
Wed Nov 6 11:08:00 GMT 2002
Please send all replies to the Cygwin users' mailing list.
This serves two purposes:
1. More people can see your problem description. This
will increase the chance that someone will know a
solution to your problem.
2. The problem and its solution are added to the
mailing-list archives. This is one of the main
knowledge databases for Cygwin. Even if a solution
is not found, then other readers are made aware of
the problem and know that it is not unique to them.
> -----Original Message-----
> From: Nathan Barham [mailto:nathan@sleepygeek.com]
> Sent: Wednesday, November 06, 2002 1:17 PM
> To: Harig, Mark A.
> Subject: Re: Can cron run ssh commands?
>
>
> Thanks for the reply,
>
> I don't have ssmtp set up yet, so I took your suggestion and
> tried redirecting
> "env" and "ssh -v" output to a file. Actually I did this
> both from the
> Administrator's command line, and from the Administrator's
> crontab creating two
> seperate files (attached) so I could compare.
>
> From the command line I ran these two commands:
>
> /usr/bin/env > testcron.admin.txt
> ssh -v baby ls 2>> testcron.admin.txt
>
> From Administrator's crontab I did this:
>
> 34 08 * * * /usr/bin/env > testcron.cron.txt
> 36 08 * * * ssh -v baby ls 2>> testcron.cron.txt
>
> In comparing the output for the env command, I see that
> Administrator's
> environment contains more environmet varibales, most notably
> those created by
> ssh-agent, which is started by keychain in Administrator's
> ~/.bash_profile
>
> SSH_AGENT_PID=517
> SSH_AUTH_SOCK=/tmp/ssh-AhbAu553/agent.553
>
> I also note that the $PATH variable for Administrator is
> prepended with Cygwin's
> /usr/local/bin:/usr/bin:/usr/sbin: while it is *not* in the
> cron/system
> environment. i.e.
>
> For Administrator:
> PATH=/usr/local/bin:/usr/bin:/usr/sbin:/c/WINNT/system32:/c/WI
> NNT: etc...
>
> For cron/system:
> PATH=/c/WINNT/system32:/c/WINNT: etc ...
>
> I'm assuming this is not the culprit however, since the ssh
> command *is* found
> even though the full path to it is not provided in the
> crontab. Is this because
> the Administrator's $PATH is being used due to context switching?
>
> In comparing the debug output from ssh -v, I see that when
> run from the command
> line as Administrator, publickey auth succeeds, but fails
> when run from cron. i.e.
>
> # From command line:
> #
> debug1: authentications that can continue:
> publickey,password,keyboard-interactive
> debug1: next auth method to try is publickey
> debug1: userauth_pubkey_agent: testing agent key
> /home/Administrator/.ssh/id_rsa
> debug1: input_userauth_pk_ok: pkalg ssh-rsa blen 149 lastkey
> 0x100cdae0 hint -1
> debug1: ssh-userauth2 successful: method publickey
> debug1: fd 6 setting O_NONBLOCK
> debug1: channel 0: new [client-session]
> debug1: send channel open 0
> debug1: Entering interactive session.
>
> # From cron:
> #
> debug1: authentications that can continue:
> publickey,password,keyboard-interactive
> debug1: next auth method to try is publickey
> debug1: try privkey: /home/Administrator/.ssh/identity
> debug1: try pubkey: /home/Administrator/.ssh/id_rsa
> debug1: input_userauth_pk_ok: pkalg ssh-rsa blen 149 lastkey
> 0x100c4548 hint 1
> debug1: PEM_read_PrivateKey failed
> debug1: read PEM private key done: type <unknown>
>
> It seems to me (in my newbie terminlogy) that either the
> cron/system environment
> needs to become aware of and use the Administrator's public key via
> Administrator's SSH_AGENT and SSH_AUTH_SOCK env variables, or
> that the SYSTEM
> user needs to have it's own public key avalable for use. I
> don't know how to
> proceed along either of these paths. Any help is much appreciated.
>
>
>
> Harig, Mark A. wrote:
> > Of course, a simpler alternative to setting up
> > 'ssmtp' with cron would be to write your
> > cron job to redirect the output of 'ssh -v ...'
> > to a file.
> >
> >
> >>-----Original Message-----
> >>From: Harig, Mark A.
> >>Sent: Tuesday, November 05, 2002 3:40 PM
> >>To: nathan@sleepygeek.com; cygwin@cygwin.com
> >>Subject: RE: Can cron run ssh commands?
> >>
> >>
> >>
> >>Try adding '-v' to your ssh command in your cron job.
> >>This assumes that you have cron's integration with
> >>email working. If you don't have the 'ssmtp' package
> >>installed (via setup.exe), then you'll want to do that
> >>so that any output is emailed to you.
> >>
> >>See: /usr/doc/Cygwin/
> >> cron.README
> >> ssmtp-<version>.README
> >>
> >>Of course, you should probably start with a simpler
> >>cron job, say, the output of '/usr/bin/env' so that
> >>you can see what cron thinks its environment is.
> >>
> >>
> >>
> >>>-----Original Message-----
> >>>From: Nathan Barham [mailto:nathan@sleepygeek.com]
> >>>Sent: Tuesday, November 05, 2002 3:09 PM
> >>>To: cygwin@cygwin.com
> >>>Subject: Can cron run ssh commands?
> >>>
> >>>
> >>>Hello all,
> >>>
> >>>I'm trying to use Cygwin to rsync between an NT 4 server and
> >>>a Win2K server,
> >>>using the "-e ssh" option to rsync. It works beautifully at
> >>>the command line
> >>>like this:
> >>>
> >>>rsync -e ssh -trzv --delete /d/winapps/
> >>
> >>Administrator@baby:/c/winapps
> >>
> >>>My problem is that this won't work from cron, nor will any of
> >>>the other Openssh
> >>>tools (scp, ssh etc). I have Cygwin sshd running as
> >>>Administrator on the remote
> >>>W2K box, i.e.*without* privsep. I have Cygwin cron running
> >>>as SYSTEM on the
> >>>local NT 4 box. I've tested cron and it works except for ssh
> >>>stuff. I also
> >>>have ssh-agent loaded on the local box (via keychain), and I
> >>>can ssh to the
> >>>remote box as Administrator without typing a passphrase.
> >>>
> >>>I'm pretty sure my problem is related to permissions of the
> >>>SYSTEM user and/or
> >>>the switching of user context, but I can't figure out what to
> >>>change. I've read
> >>>the user guide and FAQ, googled, and searched the mail
> >>>archives, but if it's
> >>>there I'm missing it. Has anyone out there managed to
> >>>automate ssh commands
> >>>from cron? If so can you please enlighten me, or at least
> >>>kick me in the
> >>>direction of self-enlightment?
> >>>
> >>>cygcheck stuff for each machine is attached.
> >>>
> >>>Thanks tons for any help.
> >>>
> >>>Nathan Barham
> >>>
> >>
> >>--
> >>Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
> >>Bug reporting: http://cygwin.com/bugs.html
> >>Documentation: http://cygwin.com/docs.html
> >>FAQ: http://cygwin.com/faq/
> >>
> >>
> >
> >
> > --
> > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
> > Bug reporting: http://cygwin.com/bugs.html
> > Documentation: http://cygwin.com/docs.html
> > FAQ: http://cygwin.com/faq/
> >
>
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: testcron.admin.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20021106/5a3c1d70/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: testcron.cron.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20021106/5a3c1d70/attachment-0001.txt>
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list