Skip to content

Instantly share code, notes, and snippets.

@fodra
Last active September 27, 2017 04:02
Show Gist options
  • Save fodra/5dcec2cb9e403817dae658e162fdb6f3 to your computer and use it in GitHub Desktop.
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>
#!/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