Skip to content

Instantly share code, notes, and snippets.

@krishnachaitanya7
Last active July 22, 2017 18:47
Show Gist options
  • Save krishnachaitanya7/2081d7b2482b5dce1f120a9bf0e79855 to your computer and use it in GitHub Desktop.
Save krishnachaitanya7/2081d7b2482b5dce1f120a9bf0e79855 to your computer and use it in GitHub Desktop.
Use this python file to copy the command of wall output to clipboard. The sender needs to login into remote system and send the output he intends the receiver to receive in the wall command. The receiver needs to run this script, please input the credentials of the same server in which the sender has logged in, whenever the script receives the o…
'''
Use this python file to copy the command of wall output to clipboard. The sender needs to login into remote system and send the output he intends the receiver to receive
in the wall command. The receiver needs to run this script, please input the credentials of the same server in which the sender has logged in, whenever the script receives the output it gets copied into clipboard of the PC of the receiver. Would this shit really work?.
'''
from paramiko import SSHClient, AutoAddPolicy
import pyperclip
ssh = SSHClient()
ssh.set_missing_host_key_policy(AutoAddPolicy())
ssh.connect('IP_Adress', username='username', password='password', key_filename='path_to_key')
outdata, errdata = '', ''
ssh_transp = ssh.get_transport()
chan = ssh_transp.open_session()
chan.setblocking(1)
chan.get_pty()
chan.exec_command('wall -n')
def copy_to_clip(string_to_copy):
list_of_strings = string_to_copy.split('\n')
list_of_strings = list_of_strings[3:]
string_to_copy = '\n'.join(list_of_strings)
pyperclip.copy(string_to_copy)
# if you want to receive constantly then comment the below line
quit()
while True: # monitoring process
# Reading from output streams
while chan.recv_ready():
outdata += chan.recv(1000)
print(copy_to_clip(outdata.decode('ascii')))
# print stdout.readlines()
while chan.recv_stderr_ready():
errdata += chan.recv_stderr(1000)
print(errdata)
if chan.exit_status_ready(): # If completed
break
ssh_transp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment