Sponsored Content
Top Forums Shell Programming and Scripting script that answers y unless output has a string "STRING" in it Post 302476455 by faizlo on Wednesday 1st of December 2010 05:14:47 PM
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,
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
projdel(1M)						  System Administration Commands					       projdel(1M)

NAME
projdel - delete a project from the system SYNOPSIS
projdel [-f filename] project DESCRIPTION
The projdel utility deletes a project from the system and makes the appropriate changes to the system file. OPTIONS
The following options are supported: -f filename Specify the project file to modify. If no filename is specified, the system project file, /etc/project, is modified. OPERANDS
The following operands are supported: project The name of the project to be deleted. EXIT STATUS
The following exit values are returned: 0 Successful completion. 2 The command syntax was invalid. A usage message for projdel is displayed. 3 An invalid argument was provided to an option. 4 The projid given with the -p option is already in use. 5 The project files contain an error. See project(4). 6 The project to be modified, group, user, or resource does not exist. 9 The project is already in use. 10 Cannot update the /etc/project file. FILES
/etc/project System project file ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |Interface stabilty | See below. | +-----------------------------+-----------------------------+ Invocation is evolving. Human readable output is unstable. SEE ALSO
projects(1), groupadd(1M), groupdel(1M), groupmod(1M), grpck(1M), logins(1M), projadd(1M), projmod(1M), useradd(1M), userdel(1M), user- mod(1M), project(4), attributes(5) DIAGNOSTICS
In case of an error, projdel prints an error message and exits with a non-zero status. NOTES
projdel deletes a project definition only on the local system. If a network name service such as NIS or LDAP is being used to supplement the local /etc/project file with additional entries, projdel cannot change information supplied by the network name service. SunOS 5.10 4 May 2004 projdel(1M)
All times are GMT -4. The time now is 10:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy