Problem in expect script with password involving trailing backslash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in expect script with password involving trailing backslash
# 1  
Old 06-20-2009
Error Problem in expect script with password involving trailing backslash

Hi all,
I have wriiten an expect script that genearates a public private key pair through ssh-keygen and then copies that key to the authorized keys file of the remote system . The problem i am facing is when i get a password for the remote machine containg a trailing backslash , the send command in expect fails to perform its function.
The expect script is as follows :
NOTE : I am passing the credentials such as password , username etc. through commandline, The password is the 5th command line argument to the script

Code:
#! /bin/sh
set $*
EXPECT_BIN=`which expect`
$EXPECT_BIN <<EOF
set timeout -1
spawn ssh-keygen -t dsa 
expect "Enter file in which to save the key (/root/.ssh/id_dsa):"
send "$KEY_FILE_PATH\r"
expect "/root/.ssh/id_dsa already exists."
expect "Overwrite (y/n)?"
send "y\r"
expect "Enter passphrase (empty for no passphrase):"
send "$PASS_PHRASE\r"
expect "Enter same passphrase again:"
send "$PASS_PHRASE\r"
expect ">"
spawn $7 $6 $3 $4
expect "$3@$4's password:"
send "$5\r"
expect ">"
send "bye\r"
EOF

I would be glad if i can get a solution for this as soon as possible
Thanks

Last edited by radoulov; 06-20-2009 at 03:19 AM.. Reason: added code tags
# 2  
Old 06-20-2009
If I'm understanding correctly you are having problems when the password contains a '\' on the end. (i.e. 'abc123\')

If this is the case, the shell is probably seeing this as a line continuation character. You will need to either escape or quote the string. Try something like abc123\\. This will tell the shell to ignore the special meaning of the slash.

Hope this helps.

-B
# 3  
Old 06-20-2009
hi,
I am already doing that before passing the password to the shell script
I even see the correct password when i try printing it in the shell script ie. with the '\'
# 4  
Old 06-20-2009
Or you may try to rewrite it all in tcl inside an expect script without a shell here document where you'll be passing arguments to the expect script directly.
Anyway, some operating systems may have problems accepting passwords with pathological characters
(I remember to have had problems with using a password with embedded # character on HP-UX).
# 5  
Old 06-20-2009
I can try that , Any other solution that sticks to expect in a shell script?
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

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

3. 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

4. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: markdjones82
2 Replies

5. 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

6. Shell Programming and Scripting

script that can give login password for "ssh" without involving STDIN

Hi Folks, I am writing a shell script that can logon to remote machine automatically. But, I am facing one problem. I am using "ssh" command in script and while login into remote machine it asks for passowrd and it stops for STDIN input for password. I want my script to supply password... (2 Replies)
Discussion started by: gydave
2 Replies

7. UNIX for Dummies Questions & Answers

problem in script involving month arithmetic

advance happy new year to all, i am having a script.The purpose of the scripts is as follows.If the current month is march,june,september or december ,inc_flg should be set to '1' otherwise inc_flg should be set to '2' month= date +"%m" if || || || ; then inc_flg = 1 else ... (6 Replies)
Discussion started by: rajarp
6 Replies

8. Shell Programming and Scripting

Shell Script -- problem reading backslash(\)!!

Hello! I am writing a program that reads a bunch of arguments from the command line,then read information from a file(passed as one of the arguments) and do some computation. The problem I am facing is when a backslash(\) is present as one of the arguments, suppose $ myprog \ abc xyz,the backslash... (2 Replies)
Discussion started by: rossi143
2 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