0

I have a couple of requirements to be satisfied using shell scripts. Since I am trio in this area, i would certainly need your help.
1) I have a script which invokes a env-function which will ask for a user input to proceed with the execution. I want my script to supply the answer to this. How can i implement this.

Doing a bit of googling pointed me to an "expect" command, which is unfortunately not installed in my system. Is there any other way to achieve this task?

2) I have another requirement like, the script should find the total number of CPUs in my pc and should append the "-j(2*no. of CPU)" to my make command.

Could somebody please shed some light into how this can be done.

Thanks,
Sen

4
  • please give a little more detail about the env-function you are invoking Commented Jul 29, 2011 at 6:39
  • That env-function is just a user-added function which is available in the environment. Commented Jul 29, 2011 at 7:21
  • did you try the read function? for e.g. read the option given by your env-function then enter the relevant answer from the script. Commented Jul 29, 2011 at 8:12
  • The word is tyro, not trio, and it is rarely used any more. Commented Jul 30, 2011 at 1:34

3 Answers 3

1

Since the first part has been answered, for the 2nd part you can try something like

#!/bin/sh 

cpu=`cat /proc/cpuinfo | grep -e '^processor' | wc -l`
jobs=$(echo "$cpu * 2" | bc)

make -j$jobs
Sign up to request clarification or add additional context in comments.

1 Comment

It is the answer below. shellscript < answers. Lets say shellscript first prompts you for an email address, and then Yes/No. Your answers file should basically have email address on one line, and Yes or No on the 2nd line. Thats it. Each line will be sent in to shellscript each time it prompts for a value. Could be shellscript or env-function.
1

I have another requirement like, the script should find the total number of CPUs in my pc

You can read the output of /proc/cpuinfo

or even better:

You can narrow down output with the following command, to display number of processors in the system:

grep processor /proc/cpuinfo

Comments

0

you can simply redirect an input to that program. An example with checkinstall:

checkinstall < /path/to/file/with/answers

3 Comments

I dont want to install a new software. Is there any other logic that can be implemented with the existing environment.
That was an example, made with checkinstall. You can do the same with any program you wish...
@Sen, for example, you might do echo y | env-function assuming the function asks the user for a "y/n" response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.