How to ignore responses in shell terminal? - linux

I am using CentOS 6.3.
How can I ignore or write 'y' when the terminal prompts a question?
For example, when I run 'yum install java-1.7.0-openjdk', it prompts me with this statement
Is this ok [y/N]:
Is there anyway I could ignore or always say yes to the question?

In the case of yum it takes an option -y that answers yes to all questions asked.
yum -y install java-1.7.0-openjdk
For other installations you can try to pipe the command yes to the process but I'm not sure it would work with every program. Try it first.
yes | yum install java-1.7.0-openjdk

Yes, you can use Spawn.
#!/usr/bin/expect -f
spawn yum install java-1.7.0-openjdk
expect "[y/N]:"
send "y\r"
interact
I'm not tested but I found "auto-terminal" here

Related

passing arguments to stdin in linux [duplicate]

This question already has answers here:
Is it possible to answer dialog questions when installing under docker?
(7 answers)
Closed last year.
I am making a Dockerfile and want to install xfce4. This is what I am currently trying:
RUN /bin/bash -c 'echo y 12 4 2 | apt install xfce4'
During installation, I am first prompted by a yes or no for installation. Then, I am prompted to give my geographical location (for some reason) and my timezone. Additionally, I am prompted to choose between gdm3 and lightdm. I am trying to pass these choices by echoing my choices and piping the output into stdin. This works for the yes or no, but fails for the rest. Any ideas on how to do this? Thanks.
Use:
DEBIAN_FRONTEND=noninteractive apt-get install -y xfce4
to install something non-interactively.

how to force yes when using preupg

I installed the 'preupg' command using:
yum -y install redhat-upgrade-tool preupgrade-assistant-contents
And I want to run the following command:
preupg
It asks if I want to continue, but I am using docker and cant say yes or no so it exits. Is there a way to silence this command?
I have tried -f and -q
To run the "preupg" tool without user interaction use
preupg --force
this will not ask for permissions and assume yes for every question.
As the preupg man page says
--force
Suppress user interaction.

Allow only apt-get update and upgrade without password prompt

I want to keep my system (and all installed packages) "always" on the latest version and therefore I'm thinking about creating special user for auto-updates. This user would get a cron-job which performs sudo apt-get update -y && sudo apt-get upgrade -y once a week.
Since this should be done automatically I'd like to edit the /etc/sudoers file (with sudo visudo of course) so that this user never gets a password prompt for these two commands.
However the only solution I found so far is to disable the password prompt only for apt-get but not for specific sub commands.
Since I want to keep it as safe as possible I'd need a way to ONLY allow update & upgrade, no other sub-commands of apt-get.
And yes, I'd also disable the execution of any other command via sudo, just to be on the safe side.
Is there any way to achieve this or is the only way to allow the execution of apt-get without password prompts (thus also allowing apt-get install)?
I'm using the Debian based distro Raspbian.
Thanks for any help!
Make a script wrapper for apt-get update and apt-get upgrade, something like this:
#!/bin/sh
apt-get update $#
and allow it in sudoers with NOPASSWD.
But need to say that I'm not really sure that it's impossible to execute some shell command using apt-get update or apt-get upgrade, so not sure that allowing to run them as root for a non-root user is secure enough.

How do I build/install protobuf 2.4.1 on CentOs (or any LINUX/UNIX system)?

Ok, so I'm kind of a complete foreigner in the UNIX/LINUX land, but I need to install profbuf 2.4.1.
I was following the instructions by doing
wget http://protobuf.googlecode.com/files/protobuf-2.4.1.tar.bz2
tar xfj protobuf-2.4.1.tar.bz2
pushd protobuf-2.4.1
./configure
make
sudo make install
I could only go as far as ./configure'. WHen I tried runningmake`, I got some error saying "No target specified and no makefile found... Stop"
Does anyone know what I might've done wrong?
Thanks!!!
You probably don't have a g++ compiler in your system or your environment variable doesn't contain the path of it. To install one on linux use the following:
yum install gcc-c++
I had met the same question before, and now I've known the reason. It's lack of corresponding library. If you are using redhat, use root permission to enter the two lines of commands:
# yum install glibc-headers
# yum install gcc-c++
If you are using ubuntu,you can enter this:
# sudo apt-get install build-essential
I've solved my question by that way. Wish you luck!

install ".run" programs with automatic yes/ok/... option

When I install packages in linux environment I can set the automatic 'yes' option, for example
yum -y install ...
or
apt-get -y install...
Is there a way to do the same but for ".run" programs. For example as,
sudo sh a.run -y
So that whenever it asks yes/no it automatically selects yes, whenever it asks for ok/cancel it selects ok, and so on...
thanks a lot in advance!!!
No, a .run command is simply a set of commands that are going to be run by sh. A particular .run file might take a -y option but in general you can't count on it. If you need to automate some stuff, consider using Expect.

Resources