Expect Script sending password with $ and symbols


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect Script sending password with $ and symbols
# 1  
Old 12-13-2010
Expect Script sending password with $ and symbols

All,
I am trying to use expect to send SFTP password because I am unable to share a key with the vendor.

They gave me a password that uses some symbols in it like $ and !

When i try to use the send command in expect it thinks the $ is a variable.

Is there anyway to have it send the actual string and not try to act like a variable?
# 2  
Old 12-13-2010
Try escaping the $ like \$
# 3  
Old 12-15-2010
Quote:
Originally Posted by Corona688
Try escaping the $ like \$
I tried that earlier and it didn't work, but then I noticed that my expect for the password prompt was different.

I fixed that and also added the escape character and it worked!

Thanks Corona.

So, on expect, you have to put the exact line that it will be expecting right? Also, anyway to get the exit status of an sftp command within expect?

Also how can I get the next command to wait util the previous command finishes?

---------- Post updated at 11:26 AM ---------- Previous update was at 10:55 AM ----------

Ok. I have one more issue. My files are not completing before it exits. It just cuts off while in the middle of transferring

How can I get my expect script to wait till the mput command is finished?
Code:
expect <<EOF | tee -a $LOGFILE
spawn sftp -o Port=$PORT $DESTUSER@$DESTSERV
expect " password:"
send "$PASSWORD\n"
sleep 2
expect "sftp>"
send "cd $DESTLOC\n"
expect "sftp>"
send "lcd $ORIGLOC\n"
expect "sftp>"
send "mput *\n"
expect "sftp>"
send "exit\n"

---------- Post updated at 12:47 PM ---------- Previous update was at 11:26 AM ----------

Ok, i got that piece resolved I just had to set the timeout.

Is there anyway to tell expect to exit if it doesn't get what it expects?

Last edited by markdjones82; 12-15-2010 at 11:16 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect script not passing password / commands ??

Newbie here. My goal is to have the expect script log into the Ubuntu 18.04 server and run two commands (lsb_release -a and ip addr) and eventually pipe the output/results to a file. For now, I would be happy to get this one command or two to run successfully. How to fix this? #!/usr/bin/expect ... (3 Replies)
Discussion started by: jacob600
3 Replies

2. Shell Programming and Scripting

1 Script Not Sending Password - Other Scripts OK

I am building FTP Script on my Bluehost VPS Server. I have several and all work great except this one.... I think there are two issues .. One with the command and One with "$" in the password. #!/bin/sh HOST=invtransfer@52.44.151.220 USER=invtransfer PASSWORD=XXX$XXX - $ is real in... (3 Replies)
Discussion started by: Wrjames2
3 Replies

3. Shell Programming and Scripting

Expect script not expecting the password prompt

I have a script that does an SSH into a remote node. It should expect the prompt and send the password. #!/usr/bin/expect set user ; set pass ; spawn ssh $user@E-Internal expect { -re "RSA key fingerprint" {send "yes\r"} timeout... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

4. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

5. Shell Programming and Scripting

Odd behaviour with Expect password update script

Hi there. I've been forced by circumstance to write an expect script to handle password updates on a number of servers. There's a mix of Solaris 8, 9, 10, RedHat and Ubuntu. There's no chance the client will allow us to hook them up to a directory, so we have to make do. This script is mostly... (0 Replies)
Discussion started by: whetu
0 Replies

6. Shell Programming and Scripting

Passing Password to SSH without using expect in a Script

How can I pass password in SSH command without using expect in a shell program. I don't have expect installed on my Solaris server. #!/bin/bash ssh user@hotname (how to supply pass in script?:wall:) Experts please help its very urgent. Shrawan Kumar Sahu (4 Replies)
Discussion started by: ss135r
4 Replies

7. UNIX for Advanced & Expert Users

Encrypt the password ,source it in a expect script...!!

Hello folks I have a conf file ,say 'pass.conf' ,which is storing ascii password : PASS1111. I need to encrypt this password once and store it in a file. I ,then need to write a script which would read this encrypted password and decrypts it.The o/p o this script shud be this decrypted... (8 Replies)
Discussion started by: ak835
8 Replies

8. Shell Programming and Scripting

Sending ssh password in a script

Is there any way to send password in a sh script, to establish a ssh connection with the remote server, without having shared the public key? The command I'm currently using is in my script is !#/bin/sh ... ssh -l user remotehost "ls -l" I have shared the public key of the local... (3 Replies)
Discussion started by: farahzaiba
3 Replies

9. Shell Programming and Scripting

Expect Script....encrypt password and use

Could someone please help me...I have an expect script. There's a need for a log in during the script and a password is required...right now the password is just a variable in the expect script...what would be the best way to put that in an encrypted flat file and have the expect script pull the... (2 Replies)
Discussion started by: cubs0729
2 Replies

10. Shell Programming and Scripting

Password changing in a Script (shell and expect)

Hi, Does anybody know how to change the password on multiple servers with a script. I have 300 Sun boxes and the password expiry is set to 30 days. Im in a process to build a script using expect. Need a help from an expert who has already done it. Regards, Vinod (1 Reply)
Discussion started by: chellam
1 Replies
Login or Register to Ask a Question