The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help in passing array of inputs to C program using script? ahjiefreak Shell Programming and Scripting 1 03-20-2008 07:36 AM
sed to replace only one istance in a file at a time ramaramarama UNIX for Dummies Questions & Answers 1 10-19-2007 01:07 PM
replace time format happyv Shell Programming and Scripting 16 04-25-2007 03:39 AM
Shell script with arguments sankar6254 Shell Programming and Scripting 3 12-22-2003 09:21 AM
Passing arguments to a script Kevin Pryke Shell Programming and Scripting 3 06-14-2002 10:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-07-2008
Dingrong Dingrong is offline
Registered User
  
 

Join Date: Oct 2008
Location: Georgia
Posts: 4
Help how replace stardard keyboard inputs by arguments at run time of a script

Hello Everybody,
Please help.

I was trying to automate the use of a third-party given shell script. The script is written to be used at run-time to collect a few variables to be provided by the user through key board, in the fashion as below:

./runcommand

please provide a file name to dump the output:
then user type in the file name
please provide the user name:
then user type in the user name
please provide password
then user type in the password
please provide role:
then the uese type in the answer to the role

I want to run this command automatically without the user interactive input as I know in advance my answers to those questions.
Ideally like:
./runcommand file_name user_name user_password user_role
or something similar that the command does not wait for the user's interaction.
How can I do that?

Thanks in advance

--Dingrong
  #2 (permalink)  
Old 10-07-2008
jyoung jyoung is offline
Registered User
  
 

Join Date: Nov 2001
Location: Flint, MI
Posts: 228
If you don't want to modify the script itself you could use expect. Here is a link:
Expect - Expect - Home Page

Also if you do a search on expect in these forums you should find examples.
  #3 (permalink)  
Old 10-07-2008
Dingrong Dingrong is offline
Registered User
  
 

Join Date: Oct 2008
Location: Georgia
Posts: 4
I found no better way but to generate on-fly a file containing answers to those questions and direct it to the runcommand.

runcommand < file_containing_answers

Thanks though.

--Dingrong
  #4 (permalink)  
Old 10-07-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
It sucks to have to use a separate file for that. If you are writing a script, keeping the information in the same script as a here document is probably preferrable.


Code:
runcommand <<answers_r_us
/path/to/dump/output
username
p455w0rd
Sarah Bernhard role
answers_r_us

Obviously, replace the placeholders with the actual input you need.
  #5 (permalink)  
Old 10-14-2008
sivakumar.rj sivakumar.rj is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 74
why cant u use the read command and check for mandatory parameters...ie. read $1,$2,$3,$4 and check $? -ne 4 then show the error message else continue with the process
  #6 (permalink)  
Old 10-14-2008
sivakumar.rj sivakumar.rj is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 74
sorry its not $? it should be $#. $? returns the status only
  #7 (permalink)  
Old 10-14-2008
sivakumar.rj sivakumar.rj is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 74
try this:assign the value of commands to a variable ie.

cmd1=$1
cmd2=$2
cmd3=$3
cmd4=$4
cmd5=$5

shift ${OPTIND}-1
if [[ $# -ne 5 ]]; then
echo "error in process"
exit 0
fi
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0