Sponsored Content
Top Forums Shell Programming and Scripting Problem in expect script with password involving trailing backslash Post 302327178 by pradeeptyagi23 on Saturday 20th of June 2009 12:47:13 AM
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
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
ASTGENKEY(8)						     Linux Programmer's Manual						      ASTGENKEY(8)

NAME
astgenkey - generates keys for for Asterisk IAX2 RSA authentication SYNOPSIS
astgenkey [ -q ] [ -n ] [ keyname ] DESCRIPTION
astgenkey This script generates an RSA private and public key pair in PEM format for use by Asterisk. The private key should be kept a secret, as it can be used to fake your system's identity. Thus by default (without the option -n ) the script will create a passphrase- encrypted copy of your secret key: without entering the passphrase you won't be able to use it. However if you want to use such a key with Asterisk, you'll have to start it interactively, because the scripts that start asterisk can't use that encrypted key. The key is identified by a name. If you don't write the name on the command-line you'll be prompted for one. The outputs of the script are: name.pub The public key: not secret. Send this to the other side. name.key The private key: secret. Those files should be copied to /var/lib/asterisk/keys (The private key: on your system. The public key: on other systems) To see the currently-installed keys from the asterisk CLI, use the command show keys OPTIONS
-q Run quietly. -n Don't encrypt the private key. SECURITY
The keys are created, using the umask of the user running the command. To create the keys in a secure manner, you should check to ensure that your umask is first set to disallow the private key from being world- readable, such as with the following commands: umask 0066 astgenkey yourkey And then make the key accessible to Asterisk (assuming you run it as user "asterisk"). chown asterisk /var/lib/asterisk/keys/yourname.* FILES
/var/lib/asterisk/keys SEE ALSO
asterisk(8), genrsa(1), rsa(1), http://www.voip-info.org/wiki-Asterisk+iax+rsa+auth AUTHOR
This manual page was written by Tzafrir Cohen <tzafrir.cohen@xorcom.com> Permission is granted to copy, distribute and/or modify this docu- ment under the terms of the GNU General Public License, Version 2 any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL-2. Asterisk May 14th, 2005 ASTGENKEY(8)
All times are GMT -4. The time now is 03:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy