Code to search for a phrase and run a command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Code to search for a phrase and run a command
# 8  
Old 07-31-2012
In Solaris, /usr/bin/grep does not support -q flag. Try to use /usr/xpg4/bin/grep, see man page for details.

You need to test the return status ($?) for the /usr/xpg4/bin/grep 'cos it does not return anything even if there is a match.
This User Gave Thanks to chihung For This Post:
# 9  
Old 07-31-2012
Quote:
Originally Posted by fop4658
hi agama,

got one more question here, as my xyz.log file keep changing daily as it has date stamp in filename just like xyz073112.log(as of today). So can we use /a/b/c/taillog.sh in first step in above code. Any means we can use taillog.sh to get rid of daily updated xyzxxx.log file
Probably. Not sure what taillog.sh does exactly, but assuming that it finds the right log, and then tails it writing to standard output, then yes you should be able to use that in place of tail -f.

I didn't notice that you indicated Solaris, so go with the suggested version of grep, or just use awk.
# 10  
Old 08-01-2012
Appreciate the quick responses, but these things wrecking my mind am completely new to unix. So anyone who can provide exact solution to my requirement. It should be like ...

1. taillog.sh is the tail log script which keeps updating when my server comes up
2. phrase to be searched for is "process completed"
3. once code find the above phrase(process completed) in taillog.sh , it should execute another ./startscript.

thanks in Advance

---------- Post updated 08-01-12 at 10:09 PM ---------- Previous update was 07-31-12 at 10:15 PM ----------

Can any one help out with a script with below requirement.,


Quote:
Originally Posted by fop4658
Appreciate the quick responses, but these things wrecking my mind am completely new to unix. So anyone who can provide exact solution to my requirement. It should be like ...

1. taillog.sh is the tail log script which keeps updating when my server comes up
2. phrase to be searched for is "process completed"
3. once code find the above phrase(process completed) in taillog.sh , it should execute another ./startscript.

thanks in Advance
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

When I run the code yesterday I am getting output,when I run same code today I am getting error?

If run the below code today its creating all directory and getting output files,I f run same code tomorrow I am getting error. can any one give suggestion to sortout this error. OSError: no such file or directory : '062518'My code looks like this import paramiko import sys import os ... (8 Replies)
Discussion started by: haribabu2229
8 Replies

2. Shell Programming and Scripting

How to find a phrase and pull all lines that follow until the phrase occurs again?

I want to burst a report by using the page number value in the report header. Each section starts with *PAGE NO:* 1 Each section might have several pages, but the next section always starts back at 1. So I want to find the "*PAGE NO:* 1" value and pull all lines that follow until "*PAGE NO:* 1"... (4 Replies)
Discussion started by: Scottie1954
4 Replies

3. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

4. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

5. Shell Programming and Scripting

Run breath-first-search find

I am trying to look for a certain file in multiple folders. When I hit the file, I want to stop going to subdirectory. For example: /foo/.target /bar/buz/.target /foo/bar/.target I want only /foo/.target /bar/buz/.target Any ideas how:)? (4 Replies)
Discussion started by: overmindxp
4 Replies

6. Shell Programming and Scripting

Is command line invocation of gnome-terminal to run more than one command possible?

Hello, I am trying to learn how to pass something more than a one-command startup for gnome-terminal. I will give an example of what I'm trying to do here: #! /bin/bash # #TODO write this for gnome and xterm USAGE=" ______________________________________________ ${0##*/} run... (0 Replies)
Discussion started by: Narnie
0 Replies

7. Shell Programming and Scripting

regarding about the (/) in the phrase

Hello, I am trying to print lines from a text file using this command gawk '/Filename:/' 11.rtf >> 22.rtf and it work ok. but if the phrase has included forward (/) something like that gawk '/File/name:/' 11.rtf >> 22.rtf it give error . so is there any manipulation when it... (1 Reply)
Discussion started by: davidkhan
1 Replies

8. Shell Programming and Scripting

Getting 15 characters after search phrase

I have data that looks like this: 2002 140 40800.0060 GPS 20 C1 25477810.2305 2002 140 41100.0060 GPS 20 C1 25298056.0453 I need to get data after certain pattern.. for example if i search for C1 it should return 25477810.2305 25298056.0453 To achieve this, it should: ... (3 Replies)
Discussion started by: bfr
3 Replies

9. Shell Programming and Scripting

convert phrase

I am converting a mysql database from myIsam to innodb. After dumping all databases to a file, I am trying to make modification: sed s/ENGINE=MyISAM/ENGINE=InnoDB/ dump_1 > dump_1_inno however, when I import the modified dump file to mysql server, I got error: ERROR 1214 (HY000) at line... (4 Replies)
Discussion started by: fredao
4 Replies

10. Shell Programming and Scripting

match a phrase

Hi, I have a these sentences. $sent1="Transactivation of wound-responsive genes containing the core sequence of the auxin-responsive element by a wound-induced protein kinase-activated transcription factor in tobacco plants."; $sent2="I branching formation in erythroid differentiation is... (4 Replies)
Discussion started by: vanitham
4 Replies
Login or Register to Ask a Question