Writing to a file multiple times with Bash

Viewed 1927

I am creating a bash script to automate some commands and I am having some trouble writing my error checking to the same file.

#!/bin/bash

touch ErrorLog.txt

bro-cut service < conn.log | sort | uniq -c > ProtocolHierarchy.txt
if [ $? -eq 0 ]; then
    echo -e "OK Protocol Hierarchy Created\n" > ErrorLog.txt
else
    echo -e "FAILED Creating Protocol Hierarchy\n" > ErrorLog.txt
fi

bro-cut id.orig_h < dns.log | sort | uniq -c > AllIPAddresses.txt

if [ $? -eq 0 ]; then
    echo -e "OK Created all IP Addresses\n" > ErrorLog.txt
else
    echo -e "FAILED Creating all IP Addresses\n" > ErrorLog.txt
fi

The goal being to have a file I can open and see that all the commands worked or failed, currently the file looks like this

-e OK Created all IP Addresses

When I would like it to look like this

OK Protocol Hierarchy Created
OK Created all IP Addresses

I am really new to bash scripting so any tips would be greatly appreciated!

1 Answers
Related