Linux – SU and Run Command Using Expect

bashexpectlinuxsu

I want to su to another user, using expect, and then run a graphical program as that user. I am using kcalc to test with:

#!/usr/bin/expect
set timeout 20
spawn su dummy
expect "Password:"
send "PASS\r";
send "kcalc\r"

I also tried eliminating the last line and changing the su to 'su dummy -c kcalc', but that didn't work either. I appreciate any help.

Best Answer

Instead of leaving account passwords sitting around the file system, why not just create a sudo command to do specifically this, and grant it with the NOPASSWD option?