Auto Switch User Script

Install expect first by:

sudo apt-get install expect

Save script in file:

#!/usr/bin/expect -f

set USER tomcat
set PASS tomcat

spawn su - $USER
expect "*assword:"
send $PASS
send "\n"

Run script by giving permission and ./
N.B. bash or sh will not work because #!/usr/bin/expect will be ignored it's not a bash script, it's an expect script.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License