Solved

An easy 50 pointer - hopefully :)

Posted on 2002-04-18
2
226 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 50 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is the meaning of filesystem loop detected? 7 1,066
Using Grep to Find a file 8 93
Linux performance issues with 100% swap usage, etc 15 93
check unix curl command return value 7 124
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

831 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