user3270211
user3270211

Reputation: 933

Python if is returning wrong

I have a if statement to check if two variables returns the same, which means the client exist. Right now the if statement should be true, I dont understand why it doesn't.

client_status= subprocess.check_output("nsostatus | grep %s | awk '{ print $1 }'" %client_name, shell=True)
print client_name
print client_status

if client_name == client_status:
        print "client already exist"
else:
        print "client doesn't exist"

When I run the script, this is what I get:

nagios-client
nagios-client
client doesn't exist

EDIT: Running it with repr()

nagios-client 
nagios-client\n

Upvotes: 0

Views: 88

Answers (1)

Josh Engelsma
Josh Engelsma

Reputation: 2646

It could be a trailing new-line or whitespace

"\n"

or

" "

... try...

if client_name.strip() == client_status.strip():

Upvotes: 4

Related Questions