Need bash script to ping the servers and rename the output file each time the script is ran

HI,
I have a file serverlist in that all host names are placed.
i have written a small script
#./testping

#! /bin/bash
for i in `cat serverlist`
do
ping $i >> output.txt
done
so now it creates a file output.txt till here fine..
now each time i run this script the output file name need to be changed..
i tried a lot but unable to do this. any quick help is appreciated

 
outputfile=$(date +%Y%m%d_%H%M%S.log)
 
and change the below line
 
ping $i >> $outputfile
1 Like

Like this?

#! /bin/bash
for i in `cat serverlist`
do
ping $i
done > output.txt_$(date +%d%m%Y%H%M%S)
1 Like

THanks it worked..

---------- Post updated at 11:22 AM ---------- Previous update was at 11:21 AM ----------

thanks...worked

 
#! /bin/bash
while read ip
do
ping $i
done < serverlist > output.txt_$$