Guest User

Untitled

a guest
Sep 6th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. subprocess call's env passing
  2. #!/usr/bin/python
  3. import os, subprocess
  4. env = os.environ.copy()
  5. env['PASSWD'] = "hello jian"
  6. retcode = subprocess.call("smbclient -L //10.60.1.11 -U Mikejian"),env=env)
  7. print retcode
  8.  
  9. def _validateSMBPassword(self, username, password):
  10. debug("call _validateSMBPassword %s:%s " % (username, password))
  11. import subprocess, os, shlex
  12. cmd = "sudo smbclient -L //%(server)s -U %(user)s"
  13. cmd = cmd % {
  14. 'server' : "10.60.1.11",
  15. 'user' : "Mikejian",
  16. }
  17. env = os.environ.copy()
  18. env['PASSWD'] = "hello jian"
  19. retcode = subprocess.call("smbclient -L //10.60.1.11 -U Mikejian",env=env,shell=True)
  20. debug("retcode:%d" % retcode)
  21. if retcode == 0:
  22. return True, True
  23. return False, False
  24.  
  25. >>> smb = smbclient.SambaClient(server="MYSERVER", share="MYSHARE",
  26. ... username='foo', password='bar', domain='baz')
  27. ...
  28. >>> print smb.listdir("/")
  29. [u'file1.txt', u'file2.txt']
  30. >>> f = smb.open('/file1.txt')
  31. >>> data = f.read()
  32. >>> f.close()
  33. >>> smb.rename(u'/file1.txt', u'/file1.old')
Add Comment
Please, Sign In to add comment