title: Can't download a file via os.system('scp (...)') whithin a python script launched via a init script
body: <p>I'm trying to download a remote file using the scp command called by os.system() in a Python script (scp.py) started as a service by a procd init script. </p>
  
  <p>This script is running on OpenWrt 15.05.1 (which uses BusyBox to implement the shell environment). SCP itself is handled by dropbear SSH (<a href="https://matt.ucc.asn.au/dropbear/dropbear.html" rel="nofollow noreferrer">https://matt.ucc.asn.au/dropbear/dropbear.html</a>)</p>
  
  <p>The code is quite simple :</p>
  
  <pre class="lang-py prettyprint-override"><code>import os
  import logging
  
  
  logging.basicConfig(level=logging.DEBUG, filename='/usr/local/www/log/scp_test.log', filemode = 'w')
  
  rc = os.system('scp -i /root/.ssh/id_rsa root@vps500141.ovh.net:/root/simon/test /tmp/hello')
  
  error_code, signal = rc &gt;&gt; 8, rc &amp; 0xFF
  
  logging.debug('error_code -&gt; {}'.format(error_code))
  logging.debug('signal -&gt; {}'.format(signal))
  </code></pre>
  
  <p>When launched in the terminal using the command "python scp.py", the program's behave well. The download is successful and produces the following output :</p>
  
  <pre class="lang-sh prettyprint-override"><code>root@S096C08:/usr/local/bin# python scp.py
  test                                           100%   24     0.0KB/s   00:00
  root@S096C08:/usr/local/bin# cat /usr/local/www/log/scp_test.log
  DEBUG:root:error_code -&gt; 0
  DEBUG:root:signal -&gt; 0
  </code></pre>
  
  <p>But this program fails to download anything when launched as a service using the command /etc/init.d/scp_test start</p>
  
  <pre class="lang-sh prettyprint-override"><code>root@S096C08:/usr/local/bin# /etc/init.d/scp_test start
  root@S096C08:/usr/local/bin# cat /usr/local/www/log/scp_test.log
  DEBUG:root:error_code -&gt; 1
  DEBUG:root:signal -&gt; 0
  </code></pre>
  
  <p>Furthermore, a quick investigation of the syslogs using the logread command shows this :</p>
  
  <pre class="lang-sh prettyprint-override"><code>Wed May 15 10:24:58 2019 daemon.err python[3156]: Host 'vps500141.ovh.net' is not in the trusted hosts file.
  Wed May 15 10:24:58 2019 daemon.err python[3156]: (ssh-rsa fingerprint md5 41:aa:2b:57:48:be:01:81:48:a3:d0:ac:b6:56:16:34)
  Wed May 15 10:24:58 2019 daemon.err python[3156]: Do you want to continue connecting? (y/n)
  Wed May 15 10:24:58 2019 daemon.err python[3156]: /usr/bin/dbclient: Connection to root@vps500141.ovh.net:22 exited: Didn't validate host key
  </code></pre>
  
  <p>vps500141.ovh.net already have an entry in /root/.ssh/known_hosts so this is quite surprising that it is not found when the script is running.</p>
  
  <p>I've also tried to add the "-o StrictHostKeyChecking=no" option to the scp command but it doesn't seems to work either.</p>
  
  <p>NB : this is the content of the init script /etc/init.d/scp_test</p>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/sh /etc/rc.common
  # Copyright (C) 2015 CZ.NIC z.s.p.o. (http://www.nic.cz/)
  
  START=99
  STOP=0
  
  USE_PROCD=1
  SCRIPT="/usr/local/bin/scp.py"
  
  start_service() {
          procd_open_instance
          procd_set_param user root
          procd_set_param command python "$SCRIPT"
          procd_set_param stderr 1
          procd_close_instance
  }
  </code></pre>