Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell scripting question - can this be done 1

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
US
Hi All,
I have no shell scripting experience. Can you tell me if the following is possible/realistically achievable?

First, I need it to issue the command "opscmd job_list" which will give a long carriage return delimited list of jobs in the print queue.

I then need to identify each line that contains the text INTERRUPTED and extract the jobnumber which is in the last 9 characters of that line.
I then need to run an additional command against each of the INTERRUPTED jobs "opscmd job_get jobnumber dest_id"
which will return a single line of text and check to see if that line contains FXQTRLY. If it contains FXQTRLY I need to issue a third command "opscmd job_hold jobnumber"

The idea is to identify jobs that are in interrupted status AND have dest_id of FXQTRLY. Unfortunately the dest_id value is not one included in the data returned by the job_list command. So I have to identify all jobs with INTERRUPTED, then test each of those jobs individually to see if they have dest_id of FXQTRLY and set them on hold if they are.

I have been attempting to automate this process using VBS to run commands through Putty but it has some severe limitations.

Can this be reasonably accomplished in a shell script on the unix server?
Does the shell scripting have the ability to store found matches in an array for processing the next step or would it have to write out to a text file then process that text file for the next step?

Any sample scripts showing how any portions of this might be accomplished? I can work well from examples and modify them to my needs.

Thanks.

At my age I still learn something new every day, but I forget two others.
 
man awk

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

Sounds like a usual system administration task. What I understood so far :
Code:
opscmd job_list | \
grep 'INTERRUPTED' | \
while read str; do
  jobnumber="${str: -9}"
  opscmd job_get "$jobnumber" dest_id | \
  grep -q 'FXQTRLY' &&
  opscmd job_hold "$jobnumber"
done

Feherke.
 
opscmd job_list | \
grep 'INTERRUPTED' | \
while read str; do
jobnumber="${str: -9}"
opscmd job_get "$jobnumber" dest_id | \
grep -q 'FXQTRLY' &&
opscmd job_hold "$jobnumber"
done

Wow, that looks simple. I will give it a try.
What would I do to echo out to the screen the original line containing INTERRUPTED once it has passed the test?
I am going to need to capture the information displayed for jobs that are actually placed on hold and write it out to a log file on a Windows share. If I can echo it out to the screen I can capture and parse the entire putty session very easily then write the appropriate entries to the log.

Thanks.

At my age I still learn something new every day, but I forget two others.
 
man tee

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

The content of lines containing 'INTERRUPTED' are set to the str variable as they are processed. So an [tt]echo "$str"[/tt] inside the [tt]while[/tt] loop will output the currently processed line.

Feherke.
 
I am getting a bad substitution error

./test.sh[4]: jobnumber="${str: -9}": bad substitution

The problem COULD be that the job number is variable in size and could be preceded by a space and followed by spaces. Would spaces in the value before or after cause the bad substitution error above?


At my age I still learn something new every day, but I forget two others.
 
Hi

You shell does not understand that parameter expansion. [tt]bash[/tt] and [tt]mksh[/tt] does.

Replace that line with :
Code:
jobnumber="$( echo "$str" | sed 's/.*\(.........\)$/\1/' )"

[gray]# or[/gray]

jobnumber="$( echo "$str" | awk '{print substr($0,length($0)-8)}' )"

Feherke.
 
I found that removing the space in "${str: -9}" got rid of the error but it did not actually pull the last 9 characters, it got the whole line.

The first of your lines above worked, have not tried the second but will play around with it to get a better understanding.

Thank you very much, this little script covers almost entirely what I need to do.
I was going to capture the putty session in a log then parse the log file for the lines where jobs were put on hold but perhaps I can get everyone here to agree that the jobs placed on hold by this process could be stored in a folder on the Unix server and I can write it out to a local file instead. I will play around with it a bit and see what I can come up with.

Thanks again.

At my age I still learn something new every day, but I forget two others.
 
Hi

theniteowl said:
I found that removing the space in "${str: -9}" got rid of the error but it did not actually pull the last 9 characters, it got the whole line.
Those two are different things :
man bash said:
${parameter:-word}
Use Default Values. If parameter is unset or null, the expan-
sion of word is substituted. Otherwise, the value of parameter
is substituted.

${parameter:eek:ffset}
${parameter:eek:ffset:length}
Substring Expansion. Expands to up to length characters of
parameter starting at the character specified by offset. [gray](...)[/gray]
Note that a negative offset must be separated from the colon by
at least one space to avoid being confused with the :- expan-
sion.

Feherke.
 
One last question.
I was only testing with a portion of the script and dropped out the portion testing for FXQTRLY.
When I added it back in I got an invalid parameter error for the grep line. What should -q be doing?
I dropped the parameter from the line and it works without error. Does not having the parameter there create potential issues as it parses through the lines?

At my age I still learn something new every day, but I forget two others.
 
Hi

In the GNU implementation of [tt]grep[/tt] -q, --quiet and --silent suppresses the output, so only the exit code is set. According to man page "-q is specified by POSIX", so I am wondering what king of [tt]grep[/tt] you could have.

Anyway, just remove the -q. Its output will be abit messed, but you can get ride of it by redirecting to the null device :
Code:
opscmd job_get "$jobnumber" dest_id | \
grep 'FXQTRLY' > /dev/null &&
opscmd job_hold "$jobnumber"

Feherke.
 
On Solaris /usr/xpg4/bin/grep has the -q option

man XPG4v2
...
If the behavior required by POSIX.2, POSIX.2a, XPG4, SUS, or
SUSv2 conflicts with historical Solaris utility behavior,
the original Solaris version of the utility is unchanged; a
new version that is standard-conforming has been provided in
/usr/xpg4/bin. If the behavior required by POSIX.1-2001 or
SUSv3 conflicts with historical Solaris utility behavior, a
new version that is standard-conforming has been provided in
/usr/xpg4/bin or in /usr/xpg6/bin. If the behavior required
by POSIX.1-2001 or SUSv3 conflicts with POSIX.2, POSIX.2a,
SUS, or SUSv2, a new version that is SUSv3 standard-
conforming has been provided in /usr/xpg6/bin.
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top