LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-14-2011, 01:56 AM   #1
pattanaikhr
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Rep: Reputation: 0
expect shell program for getting User Name and password from properties file


Hi ,
I have developed expect program for file transfer , but when I'm executing my scripts , it's only reading username not password . Below my scripts are available , please help me for getting both username and password from properties file , it's my requirement.

Properties file (userstmp)
==============
temp1 temppass1


Shell program (tmpexpect.sh)
==============
while read user
do
echo $user | xargs expect LogTrans
done < userstmp


Expect program (transfer) (LogTrans)
===============
set username [lindex $argv 0]
set password [lindex $argv 1]
spawn bash -c "scp /mnt/log/export/* $username@<remote ip>:/mnt/log/export"

expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
#expect "password:"
exp_send "$password\r"
}
}
interact


output:
$./tmpexpect.sh
spawn bash -c scp /mnt/log/export/* temp1@<remote ip>:/mnt/log/export
temp1@<remote ip>'s password:
$

Thanks for your advance help
Br,
Pattanaik
 
Old 03-14-2011, 06:14 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Try to add exp_continue in the expect/password block:
Code:
-re ".*sword.*" {
  exp_send "$password\r"
  exp_continue
}
this should force expect to process the response from the remote server and proceed with copying.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell script to change password for current user treznik Linux - General 7 09-12-2010 05:17 PM
Create user add file with default password and force user to change it? Morgandy Linux - Newbie 3 02-02-2010 06:06 PM
expect script to change user password sherimm Linux - Software 1 03-13-2009 06:36 AM
Can my shell script change the password of user ? prabhatsoni Linux - Software 1 05-27-2006 03:06 AM
how to assign password for a user in shell script mtest Programming 10 10-29-2003 07:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration