Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read password from a file within a script

Status
Not open for further replies.

mbach

Technical User
Dec 12, 2000
24
0
0
US
All,
I want to execute this command in a script but it prompts for a password.
sudo /usr/openv/netbackup/bin/bpps -a
How can I get the script to run so that it reads the password from a file instead of expecting input from standard input (keyboard)?
Thanks!!!
Mike B.
 
You probably can't - because that would be a gaping security hole.
 
Expect: It doesn't have to be that bad of a security situation.
You can use some funky homegrown obfuscation and file
permissions to make the password casually unreadable,
then either use your script to call an unencryption
routine/program or run as the privileged user.

Some very tentative code.

Code:
proc retrPw {fname} {

     if {![catch {set fd [open $fname r]}]} {
          set pw [read $fd 33] ;#length of password * sizeof(char) + 1???
         }
          close $fd
          if {[string length $pw]} {return $pw}
          if {![string length $pw]} {error "No pw found"}
}

set timeout -1
spawn sudo /usr/openv/netbackup/bin/bpps -a

     expect {
          
            -re ".*asswor.*" {
                send "[string trim [retrPw]]\r"
                exp_continue
             }

             -re "$backupsuccesspat" {
                  send_user "Success, starting backup."
                  exp_continue
             }

             -re "$Endprocpat" {
                  send_user "Done!"
                  close ; wait
              }
         }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top