LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-24-2007, 03:18 PM   #1
jmling
LQ Newbie
 
Registered: Oct 2007
Posts: 5

Rep: Reputation: 0
Unhappy how to simulte keyboard input from a bash script


Hi,

I was writing a bash script which will sudo a normal user to a super user. I donot want to manually enter the password, instead, I want to pass passwork within bash script itself. I've tried to search a lot, but still failed, could some one here to help me out? Thanks a lot in advance!

My scripting is as below:
******************************
#!/bin/bash
echo 'about to sue dough'
sudo su - ebba
< "password"
echo 'this did it'
********************************

Thanks,
Junmin
 
Old 10-24-2007, 06:34 PM   #2
larkl
Member
 
Registered: Sep 2007
Distribution: Puppy 5.2.8
Posts: 69

Rep: Reputation: 15
You might look at Expect http://expect.nist.gov/. I got it to work in a bash script where I needed to embed a password.
 
Old 10-24-2007, 06:48 PM   #3
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
This is how I did it...assumeing my UID is 500...

First edit the /etc/sudoers file and add the following:

Code:
username        ALL=(ALL)       NOPASSWD: ALL
Where username is the username of the user you want to have sudo access

Then the script would look something like this...

Code:
#!/bin/bash
#
# Only username can use this script
if [ $(id -u) -ne 500 ] ; then
  echo "You are not allowed to use this command"
  exit
fi
# Now sudo into root with out password...
sudo su -
eixt
Replace the 500 with whatever the users uid is...

-Custangro

Last edited by custangro; 10-24-2007 at 06:50 PM.
 
Old 10-24-2007, 07:17 PM   #4
jmling
LQ Newbie
 
Registered: Oct 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks, Custangro!

I think you solution will definitely work, but unfortunately, I donot have permission to modify /etc/sudoers file. You have any other suggestions to embed password within script itself?

-Junmin
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to simulte keyboard input from a bash script jmling Linux - General 5 10-26-2007 04:33 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
my mouse input is takes as keyboard input in BASH e1000 Slackware 5 12-08-2003 03:00 PM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM
bash-script input aizkorri Programming 7 07-08-2003 06:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration