I use getopts to obtain a MAC address and grep that MAC address through log files. It looks like this:
#!/bin/bash
while getopts ":m:hx:" opt; do
case $opt in
m)
cat /var/log/vmlog/Verimatrix.log | grep $OPTARG | grep VCAS080455
cat /var/log/vmlog/Verimatrix.log | grep $OPTARG | grep VCAS080285
cat /var/log/vmlog/Verimatrix.log | grep $OPTARG | grep VCAS080290
;;
h)
echo "./search_mac.sh -m <mac address> will filter the logs by mac address"
echo "./search_mac.sh -h will print this message"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
I want to export the result to a file when the -x
option is used:
./search_mac.sh -m 00067B6D87F0 -x /home/nico/extract.txt
I don't understand at this point how to obtain the argument from -x to be into my m) part of my case.
A little help would be great.
Thanks