0

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..."))
Maurice Meyer
  • 17,279
  • 4
  • 30
  • 47

1 Answers1

-1

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...")
XxJames07-
  • 1,833
  • 1
  • 4
  • 17