script that answers y unless output has a string "STRING" in it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script that answers y unless output has a string "STRING" in it
# 1  
Old 12-01-2010
script that answers y unless output has a string "STRING" in it

Hi all,

I have the following script which I use to chek the output of jobs submitted to a PBS server.
Code:
#!/bin/sh
#
#recover.sh
#

check()
{
    echo "Do you want to proceed?"
    read answer
    if [ "${answer}" == "y" ] ; then
	echo "... proceeding ..."
    else
	echo "--------- Aborting -----------"
	exit 1
    fi
}


project=$1

echo "Make a recovery def for project: ${project}"
echo "First, look at the project summary."
check

echo "get project summary --project=${project}"
get project summary --project=${project}

echo "Now get the recovery dims."
check

echo "generate strict recovery project --printQuery --project=${project}"
dims=`generate strict recovery project --printQuery --project=${project}`

echo "$dims"
echo "Translate these dims."
check

echo "translate --dims=\"${dims}\""
translate --dims="${dims}"

echo "Create the recovery definition."
check

echo "create definition --group=dzero --defName=recovery_project_${project} --dims=\"${dims}\""
create definition --group=dzero --defName=recovery_project_${project} --dims="${dims}"

echo "Now check the definition."
#check

echo "translate --summaryOnly --dims=\"__set__ recovery_project_${project}\""
translate --summaryOnly --dims="__set__ recovery_project_${project}"

echo "DONE!"
echo "Recovery def: recovery_project_${project}"

Since it needs to be fed with the job id name, and since I have 100s of these failed jobs, I made another script (I am not good at scripting yet) I made this other script:
Code:
#! /bin/sh
for JOBID in `cat jobs.txt`
do
./recover.sh $JOBID

done

where jobs.txt has all the job ids.
Now this is like a semi-automatic script, so to speak, because I have to answer these questions manually through the keyboard.
Most of the time the answer is yes, unless that output of the second check
Code:
get project summary --project=${project}

contains the string "NO FILES TO RECOVER" in this case it should be given a return (enter hit) so that it aborts the current JOBID and falls to the next JOBID in the jobs.txt (which has all the jobs names one jobs id per line)

How may I achieve an automatic yes unless the output contains NO FILES TO RECOVER?

Thanks in advance,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

2. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

3. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

6. Shell Programming and Scripting

Script to search a string which is in between "" and replace it with another character

Hi, I am trying to search a string from a text file which is in between "" (Double Quotes) (Eg: "Unix"), and replace it with a | where ever it is appearing in the text file and save the file. Please help me. -kkmdv (6 Replies)
Discussion started by: kkmdv
6 Replies

7. Shell Programming and Scripting

Shell Script to identify the line number containing a particular "string"

Hi, I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file. And then copy 200 lines above that line number to a new file. Can someone provide pointers on how to write this script or what command to be used ? Any... (2 Replies)
Discussion started by: kk2202
2 Replies

8. Shell Programming and Scripting

Shell Script to provide "answers" to SSL Cert Request

Hello, I need assistance with creating a shell script to generate SSL Certificate Requests on remote hosts. Below is my stab at this, but I cannot figure out how to pass the requested arguments into the openssl command correctly. I have a major problem with redirecting the "answers" into the... (2 Replies)
Discussion started by: azvelocat
2 Replies

9. Shell Programming and Scripting

input string="3MMTQSZ348GGMZRQWMJM4SD6M";output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6

input string="3MMTQSZ348GGMZRQWMJM4SD6M" output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6M" using linux shell script (4 Replies)
Discussion started by: pankajd
4 Replies

10. UNIX for Dummies Questions & Answers

search excat string in another string (grep "fails")

hello, i have an statement which i have to correct because it shows the wrong result. i want to search an excat string in another string, command "grep" shows the wrong result: example: STRINGS="string1 string2 string3" search_string="string" incorrect: if then echo "not... (0 Replies)
Discussion started by: bora99
0 Replies
Login or Register to Ask a Question