0

I have the following script:


LOOKUPS=/tmp/$0.LOOKUPS.$$
OK=/tmp/$0.OK.$$
KO=/tmp/$0.KO.$$
NOVENUE=/tmp/$0.NOVENUE.$$

trap "rm -f $LOOKUPS $OK $KO $NOVENUE" 0 1 2 3 4 5 13 15

tu=`$APP_SERVICE | cut -b 9-11`
date=`date +%Y%m%d`
echo "date before change: ${date}"
H=$(date +%H)
if [[ $H -ge 0 && $H -lt 9 ]]
then
        trt_date=$(date --date 'yesterday' +'%Y%m%d')
       echo "date changed: ${date}"
else
        echo "date didnt change: ${date}"
fi

grep "^$date.*lookup .. for.*" $UTP_LOG_DIR/logs.* | awk '{print $13"_"$4" "$11" "$17"="$19" "$20"="$23}' | sed 's/\[.*\]//g' | sed -e 's/string{//g' -e 's/, / /g' -e 's/=(/=/g' -e 's/)).//g' -e 's/}//g' | sort -u > $LOOKUPS

grep " OK " $LOOKUPS | awk '{print $1" "$3" "$4}' > $OK
grep " KO " $LOOKUPS | awk '{print $1" "$3" "$4}' > $KO
grep "^$date.*Can't find a venue for" $UTP_LOG_DIR/logs.* | sed 's/-$//g' | awk '{print $NF}' | sort -u > $NOVENUE

while read line
do
        if [ $(grep "$line" $OK | wc -l) -eq 0 ]
        then
                isin=$(echo $line | cut -d'_' -f1)
                feed=$(echo $line | cut -d'_' -f2,3)
                filters=$(echo "$line" | cut -d' ' -f2-)

                echo Fail lookup for $isin in feed $feed with filters: "$filters"
        fi
done < $KO

while read line
do
        if [ $(grep "$line" $OK | wc -l) -eq 0 ]
        then
                echo Cannot find venue for $line
        fi
done < $NOVENUE

To generate an output file, I redirect stdout to a file with lookup.sh > file.txt

But I need it to create the output file automatically.

7
  • 1
    What do you mean by automatically? Which file should it be saved to? Why can't you use redirection as you have proposed? Feb 13 '20 at 14:50
  • script will be placed in multiple hosts and one master host will order to execute the script and get the output file. I need that when generating the output file it uses a specific environment variable has its name. Also to avoid any problem executing the script and not output file is found.
    – anmoreira
    Feb 13 '20 at 14:55
  • Please edit your question to provide complete specs Feb 13 '20 at 14:57
  • @anmoreira note that all of what you describe can (and usually should) be handled by the process that executes the script on the different servers.
    – terdon
    Feb 13 '20 at 15:46
  • I think your problem was addressed and answered here
    – bey0nd
    Feb 13 '20 at 15:47
4

In the file, encapsulate the whole script in

{


} > file.txt

It will redirect stdout of everything within the {}.

0

You can always stuff into a file by e.g. echo Something > the-file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.