Last active
August 29, 2015 14:07
-
-
Save yureative/1a74977f37c31e89e603 to your computer and use it in GitHub Desktop.
The sample code for executing a command without `sudo` but `su -c`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from fabric.api import env, puts, sudo, settings | |
| from fabric.colors import cyan | |
| DOMAIN_LIST = '%s/.ssh/config' % os.environ['HOME'] | |
| env.use_ssh_config = True | |
| env.disable_known_hosts = True | |
| env.password = 'xxxxxx' | |
| def set_all_hosts(): | |
| with open(DOMAIN_LIST) as f: | |
| all_hosts = map(lambda y: y.split()[1], | |
| filter(lambda x: x.startswith('Host'), f.read().splitlines())) | |
| env.hosts = all_hosts | |
| puts(cyan('env.hosts = %s' % all_hosts)) | |
| def sudo_command(cmd): | |
| with settings(sudo_prefix='su -c ', sudo_prompt='Password: '): | |
| sudo(cmd) |
yureative
commented
Oct 21, 2014
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment