How can I take echo less password from the shell prompt and put it inside a variable in expect ?
Currently I am using $myscript.sh hostname "uname" mypassword
But it shows the password on the shell prompt, Can I make it echo less ? Like expect will ask me for my password and save in interval variable and also while taking password it would be echoless.
But I am using a for loop to login to more than 100 host, and I will have to type password for all of them.. :)
and also I do not want to keep my password inside the file for security risk.. Can not I assign my password to a variable at run time without echoing on the prompt ??
omarfarid
you may pass password as an argument to the script e.g. argument1, then in the expect script you do
I do not want to echo the password on prompt while providing as the argument to expect. Can't I take password like below script ?
It doesn't echo the password entered by user, it takes the input silently.
$ cat test.sh#!/usr/bin/bashecho Please, enter your Passwordread -s passecho "your password is $pass"
Not exactly what you were asking for, but you may consider using ssh passwordless keys instead of just passwords.
As you wrote something about 100 hosts, it's probably some administration task you want to automate. Take a look at dsh (distributed shell) and Cluster SSH.
$ cat /tmp/2
for i in host1 host2 host3
do
scp /tmp/123 $i:/tmp
done
Now I am running a command like these
$bssh.sh /tmp/2
and it is working fine but for 3 host I had to mention "expect "password:" 3 times,
How can I make it(expect.sh) dynamic if I have to use 100+ host ?
omarfarid
you may expect different prompts and send different responses. e.g. you expect 2 times password: prompt and response by password value. for the 3rd expect you may do like:
I have 100+ host list with the "password:" expect, it is getting exited after third expect login only..
How can I make expect to match "password:" 100+ times ?
I could not understand what you mean by "make expect to match "password:" 100+ times"
logic should be
shell script to loop for 100+ hosts that calls expect script for each host, and each time expect should change the password
beer9
ASKER
Hi Omar,
My concern is if I every time recall the expect script then I will have to provide 100 times password manually which would ultimately pass the password to my ssh client asking for password, So i am making expect to handle it, like give my password only once and provide(pass) it to any expect with 'password:' irrespective of there number of match.
#!/usr/bin/bash
#
echo "Please enter password: "
read password
export password
for host in host1 host2 host3 host4 # till host100
do
/path/to/expectscript
done
The expect script then should do
set HOST env(host)
set PASS env(password)
spawn ssh $HOST
(rest of expect script)
spawn ssh
expect "password:"
this will turn control to user to enter password