#python #linux and check (and delete if existing) a user

import pwd
 
def check_user_and_delete(user):
    try:
        if pwd.getpwnam(user) is True:
            res = sudo("userdel {}".format(user))
        if res.return_code == 0:
            print "== > User {} deleted".format(user)
        else:
            print "== > User {} not deleted".format(user)
    except KeyError:
            pass
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s