LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2009, 04:58 AM   #1
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Rep: Reputation: 30
Testing script


I would like to write a script to do that , can adivse what can i do ? thx

the logic is like that , run a test program then check the output , if the output contains the string "error is exist" , then sendmail to administrator , if no , then do nothing .


/tmp/test_program
if output contains "error is exist"
then mail to administrator
if output not contains "output is exist"
then do nothing
 
Old 09-01-2009, 05:18 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Is the output of the test_program sent to the terminal (standard output) or redirected to a file. If it standard output you can test it using:
Code:
#!/bin/bash
if /tmp/test_program | grep -q "error is exist"
then
  sendmail blah blah blah
fi
if it is redirected to a file:
Code:
#!/bin/bash
/tmp/test_program > file.log 2>&1
if grep -q "error is exist" file.log
then
  sendmail blah blah blah
fi
This is the method to use if/then to test a command. Note that you have to directly type the command after if, without any bracket or parenthesis.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Script Testing metallica1973 Programming 1 03-10-2008 10:08 AM
Testing VB script runnerpaul Programming 1 06-14-2007 09:45 AM
SMTP testing script jamesbitcoop Linux - General 5 06-03-2007 01:09 PM
Testing for enter in bash script bwysocki Programming 8 06-16-2005 09:11 AM
shell script for stress testing blackzone Programming 3 09-14-2004 12:00 AM


All times are GMT -5. The time now is 11:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration