1827703 Members
2935 Online
109967 Solutions
New Discussion

scripting

 
SOLVED
Go to solution
Sac_3
Frequent Advisor

scripting

Hi everyone,

Need a help on a script. I have explorer script which i need to automate. The script basically collects information about server hardware software etc.
I need to provide inputs to the script (need to automate this with another script). The script needs just an "enter" (to accept the default) for all the Questions that it asks. Is there a way that i can provide the input ("enter" i.e echo -e "/r") to the script in a loop etc whenever it asks for input.

Regards,
SaC

5 REPLIES 5
Srimalik
Valued Contributor

Re: scripting

if I understand your question correctly

you have a interactive script ( say explorer.sh) which requires some input at runtime.

you want a way to run this script and leave it unattended and also want the input to be give automatically.

as the default value is taken when enter is pressed.

create a file which has as many lines as there are inpupts/questions in script. say the name of the file is default_input.txt

exceute your script in while loop as

while true
do
explorer.sh < default_input.txt
done

Thanks
Sri
abandon all hope, ye who enter here..
Sac_3
Frequent Advisor

Re: scripting

What u understand is correct. Thx for the reply Sri. Im facing an issue while executing the logic that u gave i.e the script shud take input only when it requires/asks, but using this logic it is taking input every time.

So my requirement is, when the script needs input it takes input from input.txt and finally when done shud exit.

Ivan Ferreira
Honored Contributor
Solution

Re: scripting

I just tested a script like this:

echo "Enter the value for HELLO"
read HELLO
if [ -z "$HELLO" ]
then
HELLO=default
fi
echo $HELLO

echo "Enter the value for GOODBYE"
read GOODBYE
if [ -z "$GOODBYE" ]
then
GOODBYE=default
fi
echo $GOODBYE


Running in this way:

touch answer
./script < answer

It accepts all the default values.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Sac_3
Frequent Advisor

Re: scripting

U cracked it!! Thx Ivan!!
Srimalik
Valued Contributor

Re: scripting

I suggested a similar solution as Ivan.

Seems that I was not able to convay it properly. sorry for my poor english.

neways the problem is solved :).
abandon all hope, ye who enter here..