Advertisement
Guest User

fabric.py

a guest
Jul 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. from fabric import Connection
  2. from fabric import task
  3.  
  4.  
  5. ssh_conn = Connection(
  6.     host="",
  7.     user="",
  8.     connect_kwargs = {'password': ''},
  9. )
  10.  
  11. def list_folder():
  12.     with ssh_conn.cd('/webapps'):
  13.         res = ssh_conn.run('ls', hide=True)
  14.         res2 = ssh_conn.run('ls -lisat {path}'.format(path=res.stdout), hide=True)
  15.         print(res2.stdout)
  16.  
  17. def get_file_path():
  18.     with ssh_conn.cd('/tmp'):
  19.         res = ssh_conn.run('readlink -f teste.txt', hide=True)
  20.         return res.stdout
  21.  
  22. def show_file_content():
  23.     from io import BytesIO
  24.  
  25.     file_path = get_file_path()
  26.     print(file_path)
  27.     content = ssh_conn.run('cat ' + file_path, hide=True).stdout
  28.     contents = content.split('\n')
  29.     for c in contents:
  30.         if not c:
  31.             continue
  32.         print(c)
  33.     print(len(contents))
  34.  
  35. @task
  36. def check(ctx):
  37.     show_file_content()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement