You must install expect package before using this command.
http://blog.roodo.com/ystuan/archives/6128305.html
https://blog.longwin.com.tw/2011/07/expect-shell-auto-linux-2011/
We can use autoexpect tool to help us to build the script.
#!/usr/bin/expect -f
set timeout -1
spawn su -c {cp /tmp/a.txt /tmp/b.txt}
match_max 100000
expect -exact "Password: "
send -- "your_root_password\r"
expect eof
However this is not secure, it will leave your root_password in this file.
We should use sudo -S to do this job.
http://blog.roodo.com/ystuan/archives/6128305.html
https://blog.longwin.com.tw/2011/07/expect-shell-auto-linux-2011/
沒有留言:
張貼留言