Expect not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect not working
# 1  
Old 12-19-2008
Expect not working

Im trying to write a script that will change user to cyrus then reconstruct mailbox for the user defined in the parsed argument. If i was loggin in to terminal to do this manually for wendys mailbox i would do this
Code:
sudo su cyrus
/usr/bin/cyrus/bin/reconstruct -r user/wendy

That would reconstruct her mailboxes. Now i tried to do in a script using expect which i have never tried before heres my code
Code:
#! /usr/bin/expect -f

if [ ! $1 ]
then
    echo "You must enter a user name!";
    echo "Aborting!!";
    exit 1;
fi



echo "changing to user cyrus"

spawn "su cyrus"
expect "#"
send "/usr/bin/cyrus/bin/reconstruct -r user/$1"

echo "reconstructed mailbox" $1
echo "finished"
exit 1;

However this gives me the following errors

Quote:
changing to user cyrus
test.sh: line 14: spawn: command not found
couldn't read file "#": no such file or directory
test.sh: line 16: send: command not found
reconstructed mailbox wendysayers
finished
why is spawn not found? isnt it a unix command or something? What shall i do next?
# 2  
Old 12-19-2008
How did you execute your script?
# 3  
Old 12-19-2008
Code:
sudo sh test.sh wendy

# 4  
Old 12-19-2008
i found out that i should be calling the script with expect

heres the new code.
Code:
! /usr/bin/expect -f
set username [lindex $argv 0]

spawn su timgolding
expect "Password:"
send "secret\r"

expect "timgolding$"
send "sudo su cyrus\r"

expect "Password:"
send "secret\r"

expect "cyrus$"
send "/usr/bin/cyrus/bin/reconstruct -r user/$username\r"

expect eof

i save the script to /home/scripts/reconstruct_mailbox.sh
to call the script and refconstruct wendys mailbox i call

Code:
expect /home/scripts/reconstruct_mailbox.sh wendy


and it works Smilie
# 5  
Old 12-19-2008
Have you tried..?
Code:
 su cyrus -c /usr/bin/cyrus/bin/reconstruct -r user/<username>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple expect/send statements not working in shell script

Hi I am trying the following in my bash script which logs into my machine and runs a command. Trying to solve this using expect. The first expect statement is hit and it enters the address "10.10.0.10" but when the second expect statement is hit it exits #!/bin/bash expect -c ' spawn... (2 Replies)
Discussion started by: skorada
2 Replies

2. Solaris

Expect utility not working for Solaris 11

iam withdrawing this thread , It was my mistake I didn't read the code properly (0 Replies)
Discussion started by: boncuk
0 Replies

3. Shell Programming and Scripting

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

4. Shell Programming and Scripting

scp not working in expect script

Hi All, I run the scp command in shell prompt without issue, but when on expect script as below: #!/usr/bin/expect spawn scp /var/spool/sms/failed.tar.gz abc@10.10.12.2:/home/abc expect "abc@10.10.12.2's password: " send "abcfef\r" exit 0 It looks not working at all and the... (3 Replies)
Discussion started by: elingtey
3 Replies

5. Shell Programming and Scripting

Expect script not working in crontab with minicom

Hi All, I am testing expect script in command prompt without issue, but in crontab it is not working, i check the output error as below: #cat /var/log/testexp.log spawn minicom -C /var/log/minicom1.log No cursor motion capability (cm) AT+COPS=? I am new in scripting, together... (1 Reply)
Discussion started by: elingtey
1 Replies

6. Shell Programming and Scripting

Expect : exp_external not working / If not showing error

The big problem is that exp_internal isnt working... which makes it difficult to determine whats happening with the if statement. 1. why isnt exp_internal not working ? 2. Is there a better way to do the check of a file ? Im trying to find a "tighter" way to check that a file exists and has... (0 Replies)
Discussion started by: popeye
0 Replies

7. Shell Programming and Scripting

Expect Script Not working with Crontab

I have the following expect script sitting on a Linux box. === #!/usr/bin/expect -f # # backup.expect # # Expect script to backup a firewall via a SSH session # # set firewall set username set password set prompt set filename match_max 50000 spawn ssh -l... (2 Replies)
Discussion started by: alagondar
2 Replies

8. Shell Programming and Scripting

ssh is not working while calling through expect shell script

Hi, Please share you experience and way out on below error:--> #!/bin/bash -xv FILE=login.txt + FILE=login.txt CONNECT=sshlogin.exp + CONNECT=sshlogin.exp SERVERNAME=$1 + SERVERNAME=192.168.12.1 MyServer="" + MyServer= MyUser="" + MyUser= MyPassword="" + MyPassword= exec 3<&0 +... (6 Replies)
Discussion started by: manish_1678
6 Replies

9. Shell Programming and Scripting

TCL/Expect not working as expected

I am having an issue with TCL\Expect; I am passing arguments via the commandline that are read in via "lrange $argv". One of those var's is a password with characters that need to be escapaed, after escaping them an hitting enter expect is placing curly braces around my password... why?! ... (4 Replies)
Discussion started by: RiSk
4 Replies

10. Shell Programming and Scripting

Expect stdin not working

My expect script is not stopping to accept stdin puts "Hey dude, how old might you be?" gets stdin Age While running this the script does not wait for user response. What could be the problem? Pls help (0 Replies)
Discussion started by: balaji_prk
0 Replies
Login or Register to Ask a Question