networking - ssh to a computer run a command and mail the result - Ask Ubuntu


this scenario have cluster in university not connected internet. have computer connected internet.

i want ssh via computer cluster , execute command , result , mail me can check status home. means need bash-script ssh cluster login password , run command , result , mail me result.

thank you.

i finaly python code:

import paramiko import time import os   def touch(path):     open(path, 'a'):         os.utime(path, none)   ssh = paramiko.sshclient()  ssh.set_missing_host_key_policy(paramiko.autoaddpolicy())  ssh.connect('ip', port=port, username='user', password='pass',             key_filename='optional address private key')  basecommand = "command" stdin, stdout, stderr = ssh.exec_command('some command') print(stdout.readlines()) stdin, stdout, stderr = ssh.exec_command(basecommand + 'ls') print(stdout.readlines())  #for copy file  localpath = "local paths" + time.strftime("%y-%m-%d-%h-%m-%s") + ".sql"; # add date name file remotepath = "remote path" touch(localpath); sftp.get(remotepath, localpath) # download file  sftp.close() ssh.close() 

Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User