#!/bin/bash
# Generate output history file name
if [ "$#" -ne 2 ]; then
filename="history$(date +%y%m%d%H%M).txt"
else
filename=$1
fi
count=$(sudo yum history list all | sed -n 4p | tr -s ' ' | cut -d '|' -f 1)
#Empty file
>$filename
echo $filename
sp='/-\|'
echo -n ' '
for ((i = 1; i <= $((count)); i++))
do
command=`sudo yum history info $i | grep Command`
#echo $command >> $filename
re="*: "
command=${command/$re/"$i : yum "}
echo $command >> $filename
printf "\b${sp:i++%${#sp}:1} $((i*100/count))%%\r"
done