Create a shell file with the name of and add below codes, then give execute permission to that file.

# chmod +x

Set root password directly in shell script, assume that the root password is: rpasswd

#!/usr/bin/expect -f

spawn sudo -s <<EOF
expect "password:"
send -- "rpasswd\r"
expect eof

If you want to pass arguments(root password)create a file name and add below code in it.

#!/usr/bin/expect -f

set rpasswd [lindex $argv 0]
spawn su - root
expect  "password:"
send  "$rpasswd\r"

I hope, the above scripts is functional.