Bash shell scripting doubt

Hello All,

I am setting up a cron job, where i am calling a shell script to make few builds. I got struck at a point, need some expert inputs to proceed further.

The script is categorized in 5 parts and in the last part while building software it asks for few questions like:-

  1. Build mode choice
  2. normal build
  3. Copy Images
  4. Arch

User manually has to input ans for these questions:-
1
yes
n
64

The ans's are fixed and this won't change. How shall i hard-code them or do something in the script so as when script flow reaches to this point it automatically take's these value.

So far the cron job is not getting completed as it's waiting for user to key in these values manually....

I had faced similar issue while building kernel modules but there it was easier as i had to take default values always:-

yes '' | make kernel
//this worked.

But in the current scenario i need to input values......

Any inputs??

Read up on "here document". Make a wrapper script which is used to feed strings to a program expecting input:

your_script.sh << EOF
1
yes
n
64
EOF

Try this technique:

% cat script1.sh
read a
echo $a
read b
echo $b

% cat script2.sh
./script1.sh <<END
abc
123
END

% sh script2.sh
abc
123

Or just:

echo '1
yes
n
64' | your_script

From crontab you can do :

minute hour day_of_month month day_of_week your_script.sh%1%yes%n%64

Jean-Pierre.

2 Likes

Thanks Jean-Pierre, that's a new one to me!