I created a simple script to locate a user on the local machine. Despite entering any characters in the input box, the answer remains the same. I am grateful for any assistance.
#!/usr/bin/python
import subprocess
user = input("Enter username : ")
result = subprocess.getoutput("getent passwd" + user)
if result:
print(("found "+user+" user in this system."))
else:
print((""+user+" is not found..."))
>Solution :
this is because in the concatination, it should be a space that separates the database and the key:
#!/usr/bin/python
import subprocess
user = input("Enter username : ")
result = subprocess.getoutput("getent passwd " + user) #added space after 'passwd'
if result:
print(("found "+user+" user in this system."))
else:
print((""+user+" is not found..."))
also, the double parentheses are uneccessary.
#!/usr/bin/python
import subprocess
user = input("Enter username : ")
result = subprocess.getoutput("getent passwd " + user) #added space after 'passwd'
if result:
print("found "+user+" user in this system.")
else:
print(user+" is not found...")