def sudosu(user, cmd):
    cmd += ' ;exit'
prompts = []
prompts += expect('bash', cmd)
prompts += expect('assword:', env.password)
with expecting(prompts):
    run('sudo su - ' + user)

def host_type():
    sudosu('root', 'uname -s')
Running fabric scripts as root