Launch shell script if string match is found

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Launch shell script if string match is found
# 1  
Old 06-25-2012
Launch shell script if string match is found

I'm trying to write a simple shell script that looks at a given text file and if the only word in the file is 'completed', it launches another shell script.

So far I have this almost working...

if grep 'completed' $datafile

however, using this logic the secondary shell script gets launched if the word shows up anywhere in the file. Is there a way to have the logic key in on only the first word in the file?
# 2  
Old 06-25-2012
grep "^completed" $datafile && /shell/script/to/ || echo "completed is not in the first word"

# 3  
Old 06-25-2012
First you want to know if the ONLY word is "completed", later you say if the FIRST word is "completed". Which is it? Could there be multiple lines? Could the word "completed" be anywhere on the line or starting a line? Could there be lines before or after the word "completed"? Could there be error messages instead of the word "completed" that need to be accounted for? Need more info.
# 4  
Old 06-25-2012
zra1:/home/vbe/wks $ echo $CONTENT  

zra1:/home/vbe/wks $ cat test003.txt
zra1:/home/vbe/wks $ cat test003
if [ $(cat test003.txt|wc -w) -eq 1 ]
   echo still OK
   read CONTENT < test003.txt
   if [ "$CONTENT" = "completed" ]
      then echo cool
   echo not cool
zra1:/home/vbe/wks $ ./test003
still OK
zra1:/home/vbe/wks $ 

zra1:/home/vbe/wks $ cat test003.txt
zra1:/home/vbe/wks $ ./test003
not cool

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python fails to detect String Match Found

Below is my code for comparing string for Exact Match found in python. for word in jdbc_trgt.split(','): global comp comp=word.strip(); print "GloBAL:" + comp fiIn = open('list.txt').readlines() for lines in fiIn: print "line1s:" +... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. UNIX for Dummies Questions & Answers

Execute shell script and if string found while executing then exit

Hi All, I have one shell script which executes another shell script something like below -param1 -param2 In the there is one command for removing file:rm file1.bak I want whenever I execute, it will execute and if it finds string rm... (7 Replies)
Discussion started by: ORAI
7 Replies

3. Shell Programming and Scripting

Launch shell script with parameters from a webpage button

I want to create a simple html page that should contain 2 fields in which the user can write the input. Then I want to have a button that should launch a shell script with the parameters inserted by user in the fields from the webpage. This is the code behind my webpage: <html> <form... (2 Replies)
Discussion started by: black_fender
2 Replies

4. Shell Programming and Scripting

bash script search file and insert character when match found

Hi I need a bash script that can search through a text file and when it finds 'FSS1206' I need to put a Letter F 100 spaces after the second instance of FSS1206 The format is the same throughout the file I need to repeat this on every time it finds the second 'FSS1206' in the file I have... (0 Replies)
Discussion started by: firefox2k2
0 Replies

5. Programming

Eclipse C - Launch Failed. Binary Not found

Hi guys. I installed eclipse now and run "Hello World" program in C. but it gives me Launch Failed. Binary Not foundi searched in forums that say: set proper binary parser. mine is set to GNU Elf parser. could anyone help? My eclipse version is: Version: 3.6.1 Build id:... (0 Replies)
Discussion started by: majid.merkava
0 Replies

6. Shell Programming and Scripting

help with script to send email and if subject line match is found

Help with script that will check log, then find a match is found, add that as the subject line. 1. The script will always run as a deamon.. and scan the event.log file 2. when a new 101 line is added to the event.log file, have the script check position 5,6 and 7 which is the job name, which... (2 Replies)
Discussion started by: axdelg
2 Replies

7. Shell Programming and Scripting

Shell Script to launch C program

Hi there, im new too shell scripting and was wondering if it is possible to create a shell script to take in a variable and load a c program. My C program is a file monitor, and is started by using the terminal and using to following code ./monitor FileToBeMonitored is it possible to have... (12 Replies)
Discussion started by: gazmcc182
12 Replies

8. Shell Programming and Scripting

launch vnc session from unix shell script

Hi All, OS:AIX 64 bits Would like to know what is the command to launch vnc session from unix shell script so that Reports server is started from vnc session which should be launched from within the shell script. Thanks for your time! Regards, (0 Replies)
Discussion started by: a1_win
0 Replies

9. UNIX for Advanced & Expert Users

Can we launch a shell script automatically upon ssh login?

Greetings all, I'll just like to know if it is possible to launch a shell script automatically upon a user's successful login into ssh from a remote host, without adding a command parameter to the ssh command... ie. after keying in ssh username@host (not ssh username@host "command") and upon... (1 Reply)
Discussion started by: rockysfr
1 Replies

10. Shell Programming and Scripting

How to launch a Csh shell script using Excel Macro ?

Hi all. I need to use excel macro at my desktop to launch a csh script which is in a solaris environment. What is the code that i can use in macro to help me with that ? Basically, the code need to telnet or ftp to the solaris environment and just run the script and the macro will output in an... (1 Reply)
Discussion started by: Raynon
1 Replies
Login or Register to Ask a Question

Featured Tech Videos