Shell Script to Automatically Read My Password


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to Automatically Read My Password
# 1  
Old 02-22-2012
Shell Script to Automatically Read My Password

I have a shell script to run set of commands every week . I dont have a root access on the server but I can run the commands using pbrun
Code:
 
cat myscript.sh
*
*
*
pbrun command....

each time I run the script , it asks me for my password then it executes fine.
Code:
 
./myscript.sh
Password for ....

is there a way to automate the script to read my password from a file or something without me interacting with the script each time I run it.

Sincerely, Sara
# 2  
Old 02-22-2012
Code:
[noon@node2 ~]$ cat run.exp
#!/usr/bin/expect -f

if { $argc<1 } {
        send_user "usage: $argv0 <passwdfile> \n"
        exit 1 
}
set timeout 20
set passwdfile [ open [lindex $argv 0] ]
catch {spawn -noecho ./myscript.sh}
expect "Password:" {
	while {[gets $passwdfile passwd] >= 0} {
		send "$passwd\r"
		}
}
expect "*]$\ " {send "exit\r"}
close $passwdfile
expect eof
[noon@node2 ~]$ chmod +x run.exp
[noon@node2 ~]$ ./run.exp your_password_file

# 3  
Old 02-26-2012
"expect" is not defined

Quote:
Originally Posted by huaihaizi3
Code:
[noon@node2 ~]$ cat run.exp
#!/usr/bin/expect -f
 
if { $argc<1 } {
        send_user "usage: $argv0 <passwdfile> \n"
        exit 1 
}
set timeout 20
set passwdfile [ open [lindex $argv 0] ]
catch {spawn -noecho ./myscript.sh}
expect "Password:" {
    while {[gets $passwdfile passwd] >= 0} {
        send "$passwd\r"
        }
}
expect "*]$\ " {send "exit\r"}
close $passwdfile
expect eof
[noon@node2 ~]$ chmod +x run.exp
[noon@node2 ~]$ ./run.exp your_password_file

Thanks, but the command "expect" is not defined in my OS
I'm using AIX 6.1

I will be Grateful and Thankful if someone can help me with this Smilie
# 4  
Old 02-26-2012
Quote:
Originally Posted by Sara_84
...
each time I run the script , it asks me for my password then it executes fine.
Code:
 
./myscript.sh
Password for ....

is there a way to automate the script to read my password from a file or something without me interacting with the script each time I run it.
...
Code:
$
$
$ # contents of myscript.sh
$ cat -n myscript.sh
     1  #!/usr/bin/bash
     2  echo "Printing from myscript.sh"
     3  echo -n "Enter password: "
     4  read passwd
     5  echo
     6  echo "Your password is: $passwd"
     7  echo "End of myscript.sh"
$
$ # run myscript.sh and feed password when prompted
$ ./myscript.sh
Printing from myscript.sh
Enter password: hello_world

Your password is: hello_world
End of myscript.sh
$
$ # now put the password in a file, say "mypasswd.txt"
$ cat -n mypasswd.txt
     1  hello_world
$
$ # and call myscript.sh, redirecting the password from mypasswd.txt
$ ./myscript.sh < mypasswd.txt
Printing from myscript.sh
Enter password:
Your password is: hello_world
End of myscript.sh
$
$

tyler_durden
# 5  
Old 02-26-2012
Quote:
Originally Posted by durden_tyler
Code:
$
$
$ # contents of myscript.sh
$
*
*
*

tyler_durden
Im running my command using "pbrun", so the password is required by system .. I want to automate providing my password to the system each time it asks me

when I run:

Code:
 
$ pbrun commands

the system will ask me to provide my pbrun password

Code:
 
Password for sara@mydomain

# 6  
Old 02-27-2012
Quote:
Originally Posted by Sara_84
Im running my command using "pbrun", so the password is required by system .. I want to automate providing my password to the system each time it asks me

when I run:

Code:
 
$ pbrun commands

the system will ask me to provide my pbrun password

Code:
 
Password for sara@mydomain

Right, but does it work if you put your password in a file and redirect from it? If not, then explain how you set it up, how you invoked your script, and what exactly you see when the script is run.

tyler_durden
# 7  
Old 02-27-2012
Quote:
Originally Posted by durden_tyler
Right, but does it work if you put your password in a file and redirect from it? If not, then explain how you set it up, how you invoked your script, and what exactly you see when the script is run.

tyler_durden
I used your code but , the system still asks me for my password
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to automatically enter password in a script?

Hi I'm working with AIX 6.1 I would like to ssh to a server without entering password ( to monitor something) but there's no way to do that by authentication keys, so I need to write a script which can ssh to that server without entering password ( no need to hide passsword in the script, just an... (9 Replies)
Discussion started by: bobochacha29
9 Replies

2. Shell Programming and Scripting

Script to automatically enter a password

I need to retrieve thousands of lines of information from hundreds of nodes. Each node requires a passowrd in order to retrieve the information. Fortunately, the password is the same for each one of them. So I am trying to come up with a script that would allow me to include the password so I can... (0 Replies)
Discussion started by: Ernst
0 Replies

3. Shell Programming and Scripting

sftp shell script - Password read error.

Hi, I have script which does the sftp function. In the script in one place it able to read the password from file and other place files with below error. warning: has much more security than supplying the password in the clear warning: on the command line. Failed to get password: File... (0 Replies)
Discussion started by: vino_hymi
0 Replies

4. Shell Programming and Scripting

How to enter a password in the script automatically when prompted?

Hi Friends, We need to create a script which will invoke a command with diffrent parameters. The command invoked needs the password. So how automatically we can enter password in the script to the command? example.: #!/bin/ksh for par in `cat parfile` do # Here is the main command... (1 Reply)
Discussion started by: sourabhsharma
1 Replies

5. Shell Programming and Scripting

how to change root password using shell script with standard password

Hi Friends. I am new to scripting now i want to change the root password using the script with standard password. which is the easy scripting to learn for the beginner, Thanks in advance. (2 Replies)
Discussion started by: kurva
2 Replies

6. Shell Programming and Scripting

how to run shell script automatically

hi , i m trying to run bash scrip automaticially but i dont know how i can do this an anybody tell me how i can autorun shell script when i logon . thanks (9 Replies)
Discussion started by: tahir23
9 Replies

7. Shell Programming and Scripting

Script to automatically change password.

I want to write a script which will automatically take password sequentially from a file after every 10 days. i.e the passwd command should be executed automatically every 10 days and it should take the input from the password file sequentially. Has any1 got a solution?????????????? (1 Reply)
Discussion started by: rahulrathod
1 Replies

8. UNIX for Dummies Questions & Answers

How would I telnet & change user password automatically in a script

I would like to create a script that logs into a list of several servers 50+ and changes my password all at once. Every 60 days we are required to login to each system and change our passwords or else they expire and our login account is deleted. I have an idea on how I could do this but... (4 Replies)
Discussion started by: darthur
4 Replies
Login or Register to Ask a Question