Visit Our UNIX and Linux User Community


Help how replace stardard keyboard inputs by arguments at run time of a script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help how replace stardard keyboard inputs by arguments at run time of a script
# 1  
Old 10-07-2008
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  
Old 10-07-2008
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  
Old 10-07-2008
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  
Old 10-07-2008
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  
Old 10-14-2008
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  
Old 10-14-2008
sorry its not $? it should be $#. $? returns the status only
# 7  
Old 10-14-2008
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
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #973
Difficulty: Easy
GCC is the default compiler for the Linux kernel source.
True or False?

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Method to run a shell script using shortcut key in keyboard with out logging to putty

Dear All, I want to run a shell script with out logging to putty but configuring it to a keyboard short cut it windows PC. Can this be done? I want this to rename a log in a specified folder in a system Thanks (8 Replies)
Discussion started by: Chi_SL
8 Replies

2. UNIX for Dummies Questions & Answers

How to send keyboard inputs toa UNIX command executed from a shell script?

I have a unix command that prompts for 'y'. How do I run this from my shell script? (4 Replies)
Discussion started by: Sree10
4 Replies

3. Shell Programming and Scripting

Automation of keyboard inputs..like Ctrl+d and Ctrl+a

Hi..! I'm stuck with my automation of starting a process and keeping it running even after the current ssh session has exited.. So i'm trying to use command 'screen'. which is doing exactly what i wanted, But the problem is automation of the same. i will have to press Ctrl+a and Ctrl+d for... (2 Replies)
Discussion started by: chandana hs
2 Replies

4. Shell Programming and Scripting

Passing multiple run time arguments

the scenario is - If I pass 3 three arguments( run time) , it should list all .txt files from a path to temp file if I pass 2 arguments ( run time) , it should list all .csv files from the same path to another temp file the above scenario should be handled in single code and also I dont know ... (2 Replies)
Discussion started by: Prashanth B
2 Replies

5. Shell Programming and Scripting

php file unable to run shell script with arguments

echo $result=exec("./permit.sh".$_FILES); pls suggest some other method to run shell script in php .:wall::mad: (0 Replies)
Discussion started by: upvan111
0 Replies

6. Programming

Some error with number of keyboard inputs occured with this code for reversing a string..

i used a two-way linked list "node" for the code:: #include<stdio.h> #include<malloc.h> void insert(); void reverse(); struct node { char c; struct node *next; struct node *back; }*start=NULL; int main() { int n,i; (4 Replies)
Discussion started by: mscoder
4 Replies

7. Shell Programming and Scripting

Run perl script with multiple file arguments

Hello everyone, I have two types of files in a directory: *.txt *.info I have a perl script that uses these two files as arguments, and produces a result file: perl myScript.pl abc.txt abc.xml How can I run this script (in a "for" loop , looping through both types of files)... (4 Replies)
Discussion started by: ad23
4 Replies

8. Shell Programming and Scripting

Run a script parallely with different arguments

Hi! I want to run a script in parallel with different arguments. eg. start script.sh argA script.sh argB script.sh argC end Can someone please tell how to achieve this. Thanks in advance. (4 Replies)
Discussion started by: dummyix
4 Replies

9. Shell Programming and Scripting

need inputs on how i can change my script to reduce amount of time the script takes

HI , I have a list1 which consists of data that i have to search and a list2 which has the files that need to be searched .So basically i am using list1 on list2 to see if list1 data is present if found replace it .I have written the code using foreach loop for each list .This is taking the... (1 Reply)
Discussion started by: madhul2002
1 Replies

10. Shell Programming and Scripting

use several inputs as arguments in my script

Hi there, It's pretty hard for me to explain my problem because I'm affraid I'm not using the correct vocabulary. So let me describe the situation. I wrote a script that has one argument. It works like this: ~$ cat /usr/local/bin/squote echo "$@" | sed 's/'\''/'\''\\'\'\''/g; s/.*/'\''&'\''/g'... (2 Replies)
Discussion started by: chebarbudo
2 Replies

Featured Tech Videos