python on 1 text execute command code example
Example 1: execute command in python script
import os
os.system("ma Commande")
os.system("cd Documents")
Example 2: python on read text execute command
import subprocess
with open('/tmp/users.txt') as f:
userlist = [line.rstrip() for line in f]
cmds = []
for user in userlist:
cmds.append('smbmap -u {} -p p@ssw0rd -H 192.168.2.10'.format(user))
results=[]
for cmd in cmds:
results.append(subprocess.call(cmd, shell=True))
for i,result in enumerate(results):
if result == 0:
print(cmds[i])