Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

An easy 50 pointer - hopefully :)

Posted on 2002-04-18
2
Medium Priority
?
235 Views
Last Modified: 2010-04-21
Hi,

I'm writing a simple script and am having trouble with wildcards and string searching.

OK, my problem:

I have a script already called "lpck" which polls a pre-defined list of printers and executes the lpstat... command against them to see whether they are up and printing or down.

What I want my new script to do, is assign a variable to the output of the lpck script (easy part):

the_output=`lpck`

Then I want to search the_output for the word "DOWN" which will indicate that one of my printers is not functioning.

Now, I know how to test for numbers etc using the if ... then ... loop, but how do I say:

If [ "whatever the output from lpck is" matches "anything DOWN anythng" ]
then......

else.....

I guess I need to use some sort of wildcard, although I've tried this:

if [ "$printstats" = "*DOWN*" ]

And it doesn't work.

Oh, I'm running AIX 4.3 and AIX 4.2 by the way, both on RS6000's.

Thanks in advance.

Neil.
0
Comment
Question by:NTIVER
2 Comments
 
LVL 5

Accepted Solution

by:
ecw earned 200 total points
ID: 6950209
in ksh ...
  if [[ "$printstats" = *DOWN* ]]
or in ksh/sh
  if echo "$printstats" | grep DOWN > /dev/null
0
 
LVL 1

Author Comment

by:NTIVER
ID: 6950430
ecw - you're first example works beautifully - many thanks.

I thought I was close :-)

Cheers.

Neil
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question