2
How does one configure cron to parse ~/.ssh/config
to get the IP addresses and other options (such as IdentityFile) for SSH? Obviously adding source /home/user/.ssh/config
does not help.
I do not want to add the options in the script run from cron as it calls over twenty servers which have varying options. I keep the ~/.ssh/config
file updated when IP addresses or PEM keys change, and I do not want to duplicate that effort to another file to maintain.
Cron does not inherit the environment of the user configures it. Thus, for a given script:
$ cat .ssh/config
Host alpha
Hostname 1.2.3.4
User dotan
IdentityFile ~/.ssh/Dotan.pem
IdentitiesOnly yes
$ cat script.sh
#!/bin/bash
echo "Alpha"
ssh alpha dmesg
This works:
$ ./script.sh > output.log
$ cat output.log
Alpha
[73542728.181371] type=1400 audit(1397118713.764:13): apparmor="STATUS" operation="profile_replace" name="/usr/lib/connman/scripts/dhclient-script" pid=710 comm="apparmor_parser"
However, this cronjob does not work:
0 0 * * * /home/dotan/script.sh > /home/dotan/output.log
The output is:
Alpha
That proves that the script ran, but SSH failed to connect.
EDIT:
I just discovered that ssh has the option -F /home/dotan/.ssh/config
to specify a config file, but this did not resolve the issue.
I do not see how this has anything to do with cron. Can you give some more explanation of what you are trying to achieve and what your .ssh/config might look like? – Cameron Kerr – 2014-05-12T08:02:32.553
I have edited the question with more information. – dotancohen – 2014-05-12T08:16:23.343
Does
ssh -v
not give any information? – user1686 – 2014-05-12T09:28:40.823@grawity: Discovering that
ssh -v
did not give any information was key to finding the problem, see my comment to Cameron's answer below. Thank you! – dotancohen – 2014-05-12T11:25:30.157