sudo, use in script without prompt for password


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sudo, use in script without prompt for password
# 1  
Old 04-24-2009
sudo, use in script without prompt for password

I need to create an automated script where I have to use sudo to switch to multiple user so the script stops and prompts for password, Is there a way I can provide the password in same command only?

Remember that, I cannot disable the password settings of sudo as I dont have rights.
# 2  
Old 04-24-2009
According to man sudo:
Quote:
-S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.
Remember to restrict read access to the script to hide the password.
# 3  
Old 04-24-2009
[quote=EagleFlyFree;302310350]According to man sudo:

I am new to UNIX so have problems in the syntax, can you please provide me the syntax.

Currently I use

sudo -su weblogic
propmt.."pw"

how should I use it now? I tried using -S "pw" multiple places and it did not work.
# 4  
Old 04-25-2009
#!/usr/bin/expect

spawn ssh [ lindex $argv 0 ]
expect "*?assword:*"
send -- "abcd1234"
send -- "\r"
expect eof


in this example password is abcd1234, replcaethat string with your password.
for this script to execute you have to install expect.


This works if you want ot ssh into another machine.
# 5  
Old 04-25-2009
Quote:
Originally Posted by gauravgrover50
Quote:
Originally Posted by EagleFlyFree
According to man sudo:

I am new to UNIX so have problems in the syntax, can you please provide me the syntax.
Currently I use

sudo -su weblogic
propmt.."pw"

how should I use it now? I tried using -S "pw" multiple places and it did not work.
Sorry about the delay.

Code:
echo "password" | sudo -S -su weblogic

-S makes sudo "read the password from stdin", and this is what it means; it takes input from its standard input, to which you can redirect the output of something else, like echo printing out the actual password.
Again, make sure your script is only readable by the concerned users, because anyone who can cat it will see the password.

Last edited by EagleFlyFree; 04-25-2009 at 10:37 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Sudo command prompt for a password

in the /etc/sudoer file this line was added: wtolentino ALL=(ORACLE) NOPASSWD: /bin/chmod when i tried to run this command sudo -u oracle /bin/chmod 775 /appshared/applications/lpa/executables/chrpt001.rep it prompts me for a password for example: $ pwd /appshared/applications/lpa... (2 Replies)
Discussion started by: wtolentino
2 Replies

2. Shell Programming and Scripting

How to add password prompt between script ?

Hi Team, I need password prompt between this script .i want to need put password manually. Instead of adding password in script . Script pause till input password and resume again. #!/usr/bin/expect set ip spawn telnet $ip expect "login:" send "USR\r" expect "*assword*"... (3 Replies)
Discussion started by: Ganesh Mankar
3 Replies

3. Red Hat

Sudo Password Prompt over SSH

I am not sure what I am missing here. I have the following identical entry in /etc/sudoers on multiple Red Hat 6.4 servers. icinga ALL=NOPASSWD:/usr/bin/yum --security --exclude\="kernel*" check-update On one server when I enter the command over SSH as follows it works fine. ssh -t -q... (1 Reply)
Discussion started by: scotbuff
1 Replies

4. Homework & Coursework Questions

Shell Script Password Prompt

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to write a shell script that prompts the user for the password which is "lux" once the correct password... (4 Replies)
Discussion started by: Emin_Em
4 Replies

5. UNIX for Dummies Questions & Answers

Sudo -s without password prompt

hi, i have a requirement where i need to sudo to another user in the shell script.suppose consider user A and B, first user A calls a shell script and then i need to sudo to user B which executes another shell script inside the earlier one. also this needs to be automated like while sudo'ing to... (3 Replies)
Discussion started by: krk
3 Replies

6. Shell Programming and Scripting

ssh foo.com sudo command - Prompts for sudo password as visible text. Help?

I am writing a BASH script to update a webserver and then restart Apache. It looks basically like this: #!/bin/bash rsync /path/on/local/machine/ foo.com:path/on/remote/machine/ ssh foo.com sudo /etc/init.d/apache2 reloadrsync and ssh don't prompt for a password, because I have DSA encryption... (9 Replies)
Discussion started by: fluoborate
9 Replies

7. Shell Programming and Scripting

password in sudo script

salmo allikm warhmat allah wabrakato i want to do script with sudo like sudo su and want to put password in the script not get from user because i to made it startup when booting and i don't know how put in script for sudo thanks (5 Replies)
Discussion started by: pua06
5 Replies

8. Shell Programming and Scripting

enter password at prompt during a script?

I'm using rsync with the "-e ssh" option so of course it asks for a password using a prompt. Is there a way to tell a script to expect a prompt, wait for it, and give a password when it arrives? There is a way to give rsync a password as part of its options using a file, but it only works with... (2 Replies)
Discussion started by: davidstvz
2 Replies

9. OS X (Apple)

Bash script prompt for sudo password?

I'm making a script that will be a double clickable .command file and I need it to prompt for the users admin password. So far I have: if ]; then sudo -p "Please enter your admin password: " date 2>/dev/null 1>&2 if ; then echo "You entered an invalid password... (2 Replies)
Discussion started by: PatGmac
2 Replies

10. UNIX for Dummies Questions & Answers

sudo in OS X shell script without password prompt??

I've written a shell script to alter a particular preference file on OS X (10.3.9), which works fine (tested by running the script from the terminal sat in front of the box). Problem is, I now have to run this script remotely across a number of machines via remote desktop, so where I've used the... (1 Reply)
Discussion started by: Brad_GNET
1 Replies
Login or Register to Ask a Question