简体   繁体   中英

Sending password through shell script

I am using redhat linux. I was trying to write a script to enter passwords automatically thru invoking the script.

When ever i wanted to enter the build env, it asks for password twice and we have to enter that. So with the .sh file i wud be needing to enter the passwrd twice.

So is it really required to have the expect package installed in the system or can we do without this.?

the script is something like:

invokegd #cmd to enter build env
expect "*password:"
send abcde@123

I am not sure how to send it twice.. and also it says expect: not found

First need to install expect package please follow below steps:

1) Download the expect package from the below link

http://sourceforge.net/projects/expect/

2) Install the required dependecy packages "Tcl/Tk" language toolkit

     # yum install tcl

3) Install the "expect" package using the below commands

        # tar -zxvf expectx.xx.tar.gz
        # ./configure
        # make
        # make install

Then make script by adding code like

login()
{
   expect<<EOF
   expect "password"
   send "abcde@123\r"
   EOF
}
login

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM