-1

Oh my god! I have tried everything about expect. What I want to do is create a script to automate input password when changing to root in terminal. My code look like this

expect -i
spawn sudo pmset schedule sleep "{query}" expect { Password: send "password\r" }; interact;    
exit

result

expect1.1> spawn sudo pmset schedule sleep "06/19/11 23:40:00" expect { Password: echo  "lovegun\r" }; interact; exit
spawn sudo pmset schedule sleep 06/19/11 23:40:00 expect  Password: send "password\r" 
Password:

I am stuck in password: Can somebody look at my code? What is wrong with this.

expect -c '
  proc abort {} {
    puts "You have Authenticated\n"
    exit 1
  }
  spawn sudo pmset schedule sleep "{query}"
  expect {
    Password:        { send "password\n" }
    default          abort
  }
  puts "Finished OK\n"
'

Finally I found the answer

tripleee
  • 175,061
  • 34
  • 275
  • 318
Lunayo
  • 538
  • 7
  • 32
  • `send "password\n"` didn't work. I'm guessing now, so I have taken down my inaccurate answer, do you need to use `puts "$passwd \n"`, Did you see http://stackoverflow.com/questions/5575702/help-with-expect-within-a-bash-script in your research, looks promising .... Also, add a tag for your shell, bash? you'll get a lot more eyes on your problem. Good luck. – shellter Sep 16 '11 at 17:16

1 Answers1

2

If you're going to have your password buried in an expect script, you could either 1) change pmset to run set-user-id so you don't have to use sudo, or 2) give yourself NOPASSWD access to sudo so you aren't required to enter a password. Either way would keep you from having to store your password in a file.

Shizzmo
  • 16,231
  • 3
  • 23
  • 15