Score:0

Executing sudo in a script using expect works but then dropped out

hu flag

I have a script like below that basically auto execute "sudo -i", entered password and become root. Problem was that once I become root, it just froze about 10 seconds and then got dropped out back to regular user.

I checked in the /var/log/auth and /var/log/syslog, there is no error. I wonder whats wrong. Thanks

#!/usr/bin/expect
    spawn sudo -i
    expect "*?assword*"
    send -- "mypassword\r"
    expect eof
hr flag
If you want to *do stuff* once you get the root shell, you likely need an `interact` in there
bac0n avatar
cn flag
Is it the only function of the script or is it embedded in a bigger script?
hu flag
Thanks guys, it works perfectly now.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.