Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python on read text execute command

import subprocess

# read in users and strip the newlines
with open('/tmp/users.txt') as f:
    userlist = [line.rstrip() for line in f]

# get list of commands for each user
cmds = []
for user in userlist:
    cmds.append('smbmap -u {} -p p@ssw0rd -H 192.168.2.10'.format(user))

# results from the commands
results=[]

# execute the commands
for cmd in cmds:
    results.append(subprocess.call(cmd, shell=True))

# check for which worked
for i,result in enumerate(results):
    if result == 0:
        print(cmds[i])
Comment

PREVIOUS NEXT
Code Example
Python :: addDataToExp() psychopy 
Python :: when i was a young lad i was bitten by a turtle 
Python :: adding attributes and metadata to a dataset using xarray 
Python :: numpy documentation realpython 
Python :: is python3 enough for react native 
Python :: split dat file into datafram in python 
Python :: django rest framework foreign key relation giving error in serializer 
Python :: list of letter in word python 
Python :: Character in function python 3 
Python :: python how to d oa hello worl 
Python :: django datepicker mindate and maxdate 
Python :: pylatex add section without numbering 
Python :: add a new categorical column to an existing table python 
Python :: py - count if a word is present in a column 
Python :: FilePathField 
Python :: update profile rasterio pyton 
Python :: reference other libraries in library 
Python :: couple legend from twin axes python 
Python :: getting range lowest and highest values from np array 
Python :: two input string sum in django 
Python :: knn example 
Python :: pyttsx python not working 
Python :: can the function inside a function be global if the function before it is global 
Python :: Single line Commenting in Python 
Python :: identifiers in pyhton 
Python :: geopandas españa map 
Python :: break line text opencv 
Python :: zbarge / s3gui 
Python :: get window coordinates selenium 
Python :: lipa na mpesa daraja python 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =