|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 then... 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? |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
grep "^completed" $datafile && /shell/script/to/trigger.sh || echo "completed is not in the first word" |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
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
|
||||
|
||||
|
Code:
zra1:/home/vbe/wks $ echo $CONTENT
zra1:/home/vbe/wks $ cat test003.txt
completed
zra1:/home/vbe/wks $ cat test003
if [ $(cat test003.txt|wc -w) -eq 1 ]
then
echo still OK
read CONTENT < test003.txt
if [ "$CONTENT" = "completed" ]
then echo cool
fi
else
echo not cool
fi
zra1:/home/vbe/wks $ ./test003
still OK
cool
zra1:/home/vbe/wks $
zra1:/home/vbe/wks $ cat test003.txt
completed
blahblah
zra1:/home/vbe/wks $ ./test003
not cool |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl script to look for a string in a file and append few lines if the match is found | arunkumarmc | Programming | 1 | 03-04-2011 05:05 PM |
| help with script to send email and if subject line match is found | axdelg | Shell Programming and Scripting | 2 | 07-07-2010 04:43 PM |
| Shell Script to launch C program | gazmcc182 | Shell Programming and Scripting | 12 | 04-11-2010 04:04 PM |
| launch vnc session from unix shell script | a1_win | Shell Programming and Scripting | 0 | 06-05-2009 02:27 PM |
| Can we launch a shell script automatically upon ssh login? | rockysfr | UNIX for Advanced & Expert Users | 1 | 07-02-2007 10:48 PM |
|
|