sudo, use in script without prompt for password | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

sudo, use in script without prompt for password

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-23-2009
gauravgrover50 gauravgrover50 is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 12 May 2009, 4:09 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old 04-24-2009
EagleFlyFree EagleFlyFree is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 16 July 2009, 3:29 AM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #3  
Old 04-24-2009
gauravgrover50 gauravgrover50 is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 12 May 2009, 4:09 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
[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
pradeepreddy pradeepreddy is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 2 June 2009, 6:32 AM EDT
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
#!/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.
Sponsored Links
    #5  
Old 04-25-2009
EagleFlyFree EagleFlyFree is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 16 July 2009, 3:29 AM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by gauravgrover50 View Post
Quote:
Originally Posted by EagleFlyFree View Post
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 09:37 AM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sudo command with password chebarbudo Shell Programming and Scripting 1 12-29-2008 07:13 AM
verify sudo password mdpalow Shell Programming and Scripting 0 12-20-2007 09:53 PM
sudo, root password penguin-friend Linux 5 11-02-2005 02:27 AM
sudo in OS X shell script without password prompt?? Brad_GNET UNIX for Dummies Questions & Answers 1 07-29-2005 06:36 PM
rcp without password prompt scottl UNIX for Dummies Questions & Answers 1 09-15-2003 07:47 AM



All times are GMT -4. The time now is 07:39 AM.