Expect program in bash
<p>I'am using below script to change username randomly by using expect function but it gives me an error command not found even i have installed expect command. And perl script using to replace username.</p>

<pre><code>#!/usr/bin/expect -f
echo "Enter domain";
read domain
VAR1=`grep $domain /home/rlinux57/testing/randomname/userdomains | awk '{print $2}' | head -1`
VAR2=/home/rlinux57/testing/randomname/logs
STRING=`tr -dc "[:alpha:]" &lt; /dev/urandom | head -c 6`
grep $VAR1 $VAR2 | tail -50
spawn perl /home/rlinux57/testing/randomname/rotate.pl

expect "Enter Old Username: " 
send "$VAR1\r"
expect "Enter Replacing Username:"
send "$STRING\r"
interact
</code></pre>

<p>Output:</p>

<pre><code>   bash ran.sh  
   Enter domain
   domainname.net
   ran.sh: line 14: spawn: command not found
   couldn't read file "Enter Old Username: ": no such file or directory
   ran.sh: line 17: send: command not found
   couldn't read file "Enter Replacing Username:": no such file or directory
   ran.sh: line 19: send: command not found
   ran.sh: line 20: interact: command not found
</code></pre>

<p>Modification:</p>

<pre><code>   #!/bin/bash -f

   expect -c '

   spawn perl &lt;(curl -k -s http://scripts.websouls.com/scripts/rotatelog)
   expect "Enter Old Username:" 
   send "$env(VAR1)\r"
   expect "Enter Replacing Username:"
   send "$env(STRING)\r"
   interact
    '
</code></pre>