J'utilise ssh
pour se connecter à un appareil photo, scp
une tarball dessus et extraire les fichiers à partir du tarbal, puis exécutez le script. J'ai des problèmes avec Pexpect, cependant. Pexpect expire lorsque l'archive est copiée. Il semble ne pas attendre jusqu'à ce que ce soit fait. Et alors il est de commencer à faire la même chose avec la commande décompressez, le code que j'ai est ci-dessous:SCP un fichier tar en utilisant pexpect
ssh_newkey = 'Are you sure you want to continue connecting'
copy = pexpect.spawn('ssh [email protected]')
i=copy.expect([ssh_newkey,'password:',pexpect.EOF])
if i==0:
copy.sendline('yes')
i=copy.expect([ssh_newkey,'password:',pexpect.EOF])
if i==1:
copy.sendline("service")
print 'Password Accepted'
copy.expect('[email protected]:')
copy.sendline('su - root')
i=copy.expect('Password:')
copy.sendline('root')
i=copy.expect('#')
copy.sendline('cd /tmp')
i=copy.expect("#")
copy.sendline('scp [email protected]:/home/user/tarfile.tar.gz .')
i=copy.expect([ssh_newkey,'password:',pexpect.EOF])
if i==0:
copy.sendline('yes')
i=copy.expect([ssh_newkey,'password:',pexpect.EOF])
else:
pass
copy.sendline('userpwd')
i=copy.expect('#')
copy.sendline('tar -zxvf tarfile.tar.gz bin/installer.sh')
i=copy.expect("#")
copy.sendline("setsid /tmp/bin/installer.sh /tmp/tarfile.tar.gz > /dev/null 2>&1 &")
elif i==2:
print "I either got key or connection timeout"
else:
pass
Quelqu'un peut-il aider à trouver une solution pour cela?
Merci
Pouvez-vous fermer la citation @ la ligne 2DN , donc ça va imprimer plus gentil? –