Solved

An easy 50 pointer - hopefully :)

Posted on 2002-04-18
2
223 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
Comment Utility
in ksh ...
  if [[ "$printstats" = *DOWN* ]]
or in ksh/sh
  if echo "$printstats" | grep DOWN > /dev/null
0
 
LVL 1

Author Comment

by:NTIVER
Comment Utility
ecw - you're first example works beautifully - many thanks.

I thought I was close :-)

Cheers.

Neil
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now