ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
oops Sorry, completely forgot about the yes / no questions.
Try this instead:
Code:
exec 3<$project
while read -r JOBID <&3
do
<your stuff here>
done
exec 3<&-
Also, you may wish to make the yes / no questions more robust as a user may enter y, Y, yes, Yes or even ok.
Perhaps you should suggest possible answers (help get rid of things like ok) and then look at controlling the case (upper or lower)
As far as I can tell, I am still using this script:
Code:
#! /bin/bash
for JOBID in `cat jobs-ids.txt`
do
./make_recovery.sh $JOBID
done
which is kind of auto-manual. It feeds the jobs-ids one by one, but I have to answer with y (if I really want to say y) for any of the questions in the main script, otherwise a hit on enter and I move to the next job id.
As you may know now, I have few questions that should be answered with y or the script will abort.
For the first question:
Code:
echo "Make a recovery def for project: ${project}"
echo "First, look at the project summary."
check
The answer should be y
then the script goes to the second question. This time again, the answer should be y and the output message may or may not contain the statement "NO FILES TO RECOVER".
What I hope to do is to have the first two answers as y automatically, and when the message "NO FILES TO RECOVER" is spelled out, the script should proceed to the next JOBID in the jobs-ids.txt. How is this possible.
so I had to it manually as I described in my last post. But, since this would really help me a lot for all my jobs, I wonder if it is possible to get some help from you to make it fully functional and fully processed without me having to reply with either y or [enter]
So, is there a way to check the output for the certain string "STRING" and decides the answer based on it?
Yes. Assuming my previous suggestion worked:
Code:
#! /bin/bash
for JOBID in `cat jobs-ids.txt`
do
case $( yes | ./make_recovery.sh $JOBID) in
*'first string you are looking for'* )
<whatever you want when it is found>
;;
*'second string you are looking for'* )
<whatever you want when it is found>
;;
* )
<whatever you want when none of the strings are found>
;;
esac
done
The * in front and after the strings makes the case statement match them if they appear anywhere in the output.
the output is 10s of lines, if not 100s, but the final 4 lines contain the string "NO FILES TO RECOVER", so I guess I need grep for that.
I am sorry, but I am getting confused now.
I have tried to google this but did not know which term to use for search, I used "check output for a certain string" but couldn't find what I am looking for.
So which command is returning the 10s / 100s of lines? If you know it will definitely be in the last line then a simple tail command will show you what you want.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.