I am writing a shell (after 6-7 months)that has to receive text from another shell, check if the first line in the text has a key word and then execute different shell.I could come up with the below program structure, please suggest me if there is a better way to do it or please help me with this script.
More deatails:
Have script1, arg1, Myscript (to be writen), triggerScript
*********
# MyScript, should check for keyword inside the text output from script1 and execute triggerScript
arg1="$1"
script1=/./../script
searchText="`$script1 "arg1"`" (Need to get first line of the text out from script1.)
if [ grep for "Keyword" in $searchText && exists/True] ]
then
./tiggerScript (execute trigger script)
fi
********
so you wanna search the keyword in the o/p of the script??
then redirect the o/p of the script to a variable or to a file(to be safe and more specific result) then grep for that word and rest is as you written
My trigger script was not getting executed even though I have a key word, If condition is not proper i guess. Plz suggest a generic If condition for my block of code.
this what I wrote, forgive me if there are blunders
Args1="$1"
Args2="$2"
SCRIPT1=/u01/.././script1
searchText="`$SCRIPT1 "$Args1"`" (Here i need to get first line from the script1 output which may have multiple text lines)
if [$searchTest|grep "keyword" >/dev/null] ]
then
/u01/../triggerScript "Arg2"
fi
Args1="$1"
Args2="$2"
/u01/.././script1 >> SCRIPT1.txt
searchtext=`head -1 SCRIPT1.txt` #this will get the first line of the o/p of first script
echo "$searchtext"|grep -q "keyword"
if [ $? -eq 0 ] ; then
/u01/../triggerScript "Arg2"
fi
Args1="$1"
Args2="$2"
SCRIPT1=/u01/.././script1
$SCRIPT1 $Args1 | head -1 | grep "$Args2" > /dev/null
if [ $? -eq 0 ]; then
/u01/../triggerScript "Arg2"
fi
BTW:
+ Provide more descriptive argument names
+ SCRIPT1 variable is probably unnecessary. Just use the name explicitly.
+ /u01/../script1 -- means the script1 is in the / root directory. The ".." is certainly odd here.
+ You had 2 ]] 's.
+ I think you meant "searchText" in your grep line.
is there a way with out creating any auxiliary files in between coz this script which we write will be used by 100s of folks.I really appreciate your time and help.
thanks quirkasaurus.Sorry, I was addressing Vidhyadhar85.
Here is the corrected version, had typos in my post.
****************************************
Args1="$1" (Args1 is script specific argument that will make script1 to spit bunch of text lines )
Args2="$2"
SCRIPT1=/u01/{directory1}/{directory12}/script1
searchText="`$SCRIPT1 "$Args1"`" (Here i need to get first line from the script1 output which may have multiple text lines)
if [$searchText|grep "keyword" >/dev/null ]
then
/u01/../triggerScript "Arg2"
fi