3

Problem: When running ssh-keyscan in cron it emails me the output of ssh-keyscan every day. The email simply contains the following.

# <hostname> SSH-2.0-OpenSSH_5.3

My (simplified) cron job:

host=`uname -n`
SSHKey=`ssh-keyscan $host`
echo $SSHKey >> /root/.ssh/known_hosts

My question: How do I prevent ssh-keyscan from writing anything to the shell?

8

redirect stderr into /dev/null

host=`uname -n`
SSHKey=`ssh-keyscan $host 2> /dev/null`
echo $SSHKey >> /root/.ssh/known_hosts
3
  • Thanks, I was assuming that output was stdout not stderr and I was redirecting the wrong stream in my tests. I appreciate your quick reply.
    – tbenz9
    Aug 12 '15 at 17:05
  • Is there a reason to use `…` and not $(…)
    – A.B.
    Aug 12 '15 at 20:18
  • it has the same meaning as you can see in manual page for bash
    – Jakuje
    Aug 12 '15 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.