How to capture hostnames or ip address in the log files generated?

Team,

I have prepared a script which I run from my remote machine(Jump-box)server
Below is the script

FILEDATE=`date +%F`
LOGFILE=/home/abc/scripts/xyz.$FILEDATE.log
find /home/abc/scripts/xyz.*.log -type f -mtime -3 -delete
touch $LOGFILE
exec 1>$LOGFILE 2>&1
#healthcheck batch runs here
for ip_addr in $(cat ip_abc);do 
ssh ${ip_addr} "bash -s" < my_script
done

There are 10 different ip address in my ip_abc file,and my_script file has a series of similar commands which i capture in my logs.Now when i run the above script, it runs successfully, but i need to add one more pointer to classify in my logs like the start and end of each ip address(mentioned below).

eg:batch <hostname or ip_address> begins
    batch <hostname or ip_address> ends

This will enable me identify easily that the logs are for the specific ipaddress or the hostnames.

Regards
Whizkid

Try adding

echo "batch $ip_addr begins"

before the ssh command and

echo "batch $ip_addr ends"

after the ssh command.

1 Like