So I'm attempting to grab some syslogs from a file like this one.
$date INT-FW01 : %ASA-6-106100: access-list inside denied udp inside/172.29.2.101(1039) -> outside/192.203.230.10(53) hit-cnt 1 first hit [0xd820e56a, 0x0]
I will be replacing the time-stamp and IP addresses of the individual logs which are taken from the file and stored inside an array. here is my code:
#!/bin/bash
file=log_store
gen_ip() {
echo $((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256))
}
timestamp() {
date +"%b %d %H:%M:%S"
}
ip=$(gen_ip)
date=$(timestamp)
if [ -e $file ]; then
readarray -t logs < $file
else
echo "$file is not present"
fi
cmd='cmd=${logs[0]}'
eval $cmd
echo $cmd
this code seems to echo the first array item but it isn't replacing the $date from the file, it simply prints "$date". From my tests the eval seems to work on other arrays I've defined inside the program except for the log array so i'm a little stuck!