How to write automated interactive shell script?

Hello everyone, I just want to write a shell script for automatic feeding the username and password prompts when running my commands,
I tried this one but it did not work. Please help me for any way out.

#!/bin/bash
#!/usr/bin/expect

cd ~/workspace/mimosanetworks_mimosa-nms

ls -ltr

spawn sudo git pull

expect "[sudo] password for sandeep:"

send "sandeep123\n"

expect "Username :"

send "sandeep\n"

expect "Password :"

send "sandeep121\n"

Whats the problem are you facing? I guess if you just do some digging around the forum u will get many except script examples.

I get the following output

sandeep@K2-Sandeep-08:~$ ./checkout.sh 
total 64
./checkout.sh: line 8: spawn: command not found
couldn't read file "Username:": no such file or directory
./checkout.sh: line 16: send: command not found
couldn't read file "Password:": no such file or directory
./checkout.sh: line 20: send: command not found

do you have expect utility installed on your server?

Yes. Expect utility is installed. I donno whether send and spawn utitlity exists? as I tried through "apt-get", der is no such utility

i would strongly advise against scripting a password-required process for the usual security reasons ...

anyways, see if a here document could work for you ... (see sample below) ...

otto@susegeek:~> su - << EOF
> B0r3d2!
> id
> ps
> EOF
Password: uid=0(root) gid=0(root) groups=0(root)
  PID TTY          TIME CMD
 6423 pts/1    00:00:00 su
 6426 pts/1    00:00:00 bash
 6455 pts/1    00:00:00 ps
otto@susegeek:~>