Expect command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect command
# 1  
Old 04-03-2012
Expect command

Hi, I wanted to automate the scp command where i do not want to enter the password each time. So thought of using expect command. Script is executing without any issues but files are not copied to remote server. Can any one help me?

Below is my shell script..

Code:
#!/bin/ksh

TMP_FILE="/tmp/testestest"
/usr/bin/expect -d <<EOD
spawn /usr/bin/scp $TMP_FILE user2@123.123.123.123:/tmp/backup/logs/
expect "password:"  { send "user1234\r" }
EOD

Output
-------
Code:
here
expect version 5.42.1
argv[0] = /usr/bin/expect  argv[1] = -d
set argc 0
set argv0 "/usr/bin/expect"
set argv ""
executing commands from command file
spawn /usr/bin/scp /tmp/testestest user2@123.123.123.123:/tmp/backup/logs/
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {31719550}

expect: does "" (spawn_id exp4) match glob pattern "password:"? no
********************************************************************************
* This system was LDAP clientized on Wed Aug  3 14:49:58 CUT 2011              *
********************************************************************************

expect: does "********************************************************************************\r\n* This system was LDAP clientized on Wed Aug  3 14:49:58 CUT 2011              *\r\n********************************************************************************\r\n" (spawn_id exp4) match glob pattern "password:"? no
user2@123.123.123.123's password:
expect: does "********************************************************************************\r\n* This system was LDAP clientized on Wed Aug  3 14:49:58 CUT 2011              *\r\n********************************************************************************\r\nwsadmin@159.202.157.176's password: " (spawn_id exp4) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "********************************************************************************\r\n* This system was LDAP clientized on Wed Aug  3 14:49:58 CUT 2011              *\r\n********************************************************************************\r\nwsadmin@159.202.157.176's password:"
send: sending "user1234\r" to { exp4 }
at end

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 04-03-2012 at 12:17 PM..
# 2  
Old 04-03-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

(duplicate is here
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect command when triggered by launchd

Hi folks, Im having trouble with an expect command in a shell script I use to back up mac os x servers. This one is being run on a 10.8.2 Server as part of a larger bash script. The script executes perfectly all the way through when triggered on the command line, but when launchd triggers it at... (4 Replies)
Discussion started by: rowie718
4 Replies

2. Shell Programming and Scripting

Expect command- need help

Hi All, I need help in making my script run perfectly as expected. This is a snippet from my script. I am trying to read the ";" from the below output using the expect command, but the command is not detecting it. Could you please help me correct the expect string? Snippet: ---- ---... (2 Replies)
Discussion started by: sonicj
2 Replies

3. Shell Programming and Scripting

Help with expect command

Hi, I am using following commands in my script to send a password to scp command. Everything is working fine except that I need a return code from the scp command. Do any one have an idea how to receive the exit code of scp command from expect. /usr/bin/expect << EOF spawn -noecho scp -pq... (0 Replies)
Discussion started by: pvamsikr
0 Replies

4. Shell Programming and Scripting

Expect command on Linux

Hello All, can anyone let me know i can i execute scripts using expect on remote hosts. Regards Ankit (2 Replies)
Discussion started by: ajaincv
2 Replies

5. Shell Programming and Scripting

How to use expect command?

Hi, 10.152.165.217 and 10.152.165.218 are two servers that i use. I would like to access 218 from 217 using expect command. i'm not aware of how to use the command. Could anyone help me with it with a script snippet -> imagine abc be the user in 217 with passwd abc123 -> imagine xyz be... (1 Reply)
Discussion started by: kaushik_87
1 Replies

6. Shell Programming and Scripting

su with expect...in a single command?

Hello I am trying su from one user to another in a script. Now the person who runs the script(user) cannot have the password for the user he is su -ing to (webuser) . Here is my script which performs su . This is a hack job based on a few hours of web search. #!/usr/local/bin/expect set... (5 Replies)
Discussion started by: pkabali
5 Replies

7. Shell Programming and Scripting

another command similar to expect

Hi , I just wondering if there is any command that works similar to the expect command. I'm trying to setup a korn shell script that goes to remote servers and executes a command likes : su - username -c "script to execute " but then it'll prompt for the password so if I can provide... (1 Reply)
Discussion started by: arizah
1 Replies

8. Shell Programming and Scripting

Expect: run a command first before sending

Hello Expect experts, Is it possible with Expect to run a command first when an expected phrase is outputted by a spawned program? Before sending an answer to the spawned program that is... Thanks a lot. (2 Replies)
Discussion started by: Tr00tY
2 Replies

9. Linux

how to use expect command?

Hello, I am doing a project which asks me to enter password 4 times in a row. I need to enter the same password 4 times. My target is to enter password once and apply it 4 times. My friend told me to use "expect" command. Can you please give me a sample code to do so. sample command :- $ ssh... (1 Reply)
Discussion started by: nsharath
1 Replies

10. Shell Programming and Scripting

Expect and auto expect command

I need to run a remote application(GUI) in a client.i.e on running a script in the client machine i should get the GUI application which is running in the server by providing password through the script.Will expect or autoexpect command suit for this scenario? could anyone help me by posting some... (0 Replies)
Discussion started by: arun_v
0 Replies
Login or Register to Ask a Question