|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
each time I run the script , it asks me for my password then it executes fine. 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 |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
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 |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
"expect" is not defined
Quote:
I'm using AIX 6.1 I will be Grateful and Thankful if someone can help me with this ![]() |
|
#4
|
||||
|
||||
|
Quote:
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 |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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 |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Quote:
tyler_durden |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
I used your code but , the system still asks me for my password
|
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script to automatically enter a password | Ernst | Shell Programming and Scripting | 0 | 01-18-2011 10:03 AM |
| sftp shell script - Password read error. | vino_hymi | Shell Programming and Scripting | 0 | 10-25-2010 02:50 AM |
| How to enter a password in the script automatically when prompted? | sourabhsharma | Shell Programming and Scripting | 1 | 07-08-2009 01:36 PM |
| Script to automatically change password. | rahulrathod | Shell Programming and Scripting | 1 | 10-04-2004 08:33 AM |
| How would I telnet & change user password automatically in a script | darthur | UNIX for Dummies Questions & Answers | 4 | 01-14-2002 10:40 AM |
|
|