Last active
September 27, 2017 04:02
-
-
Save fodra/5dcec2cb9e403817dae658e162fdb6f3 to your computer and use it in GitHub Desktop.
This will execute a command that requires root access. Usage ./sudo_command.exp <password> <command>
This file contains 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
#!/usr/bin/expect | |
# argv 0 is password | |
# argv 1 is command e.g. kextload -b info.stichling.USBCDCACMControl | |
# get the password from the commandline | |
set password [lindex $argv 0] | |
# get the command from the commandline | |
set command "sudo [lindex $argv 1]" | |
# Used for debugging the program arguments | |
# puts "$password" | |
# puts "$command" | |
# use eval to create the parameterized command | |
eval spawn $command | |
# simulate entering the user's password so | |
# so the user doesn't have to. | |
expect { | |
"Password:" { | |
send "$password\r" | |
exp_continue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment