Hi, I have a shell script which analyses the log folder for a specific string and throws me the output. I have used for loop since it does this in multiple servers. Now I want to save the output in a excel in the below format. Can someone please help?
This is the second time that this has been posted, please contact a moderator if you think that you have posted on the wrong forum. You should also post your code, it will allow people to deliver more targeted help to you.
#!/bin/sh
TimeStamp=$(/bin/date "+%Y-%m-%d")
servernums="$(seq 10 16) 19"
# print args on one line separated by ","
myprint(){
[ $# -ge 1 ] || return
printf "%s" "$1"
shift
[ $# -ge 1 ] &&
printf ",%s" "$@"
printf "\n"
}
# line one
myprint $(
for num in $servernums; do
echo "server${num}"
done
)
# line two
myprint $(
for num in $servernums; do
grep -c 'Execution Complete ' App_log_${TimeStamp}_server${num}*
done
)
Save the output as .csv, then Excel should be able to open it.
Great ! Both the code worked. Thankyou so much. Can you also help me with the code to append the output the as a row to the excel everytime when this script gets executed ?
Date server10 server 11 server12 server13
Today date 57 124 234 67
So, whenever I run the script the second row i.e., the counts row alone should get appended and everyday a new second row should get appended in the below cells. The output I am expecting should look like
Date server10 server 11 server12 server13
Today date 57 124 234 67
Tomorrow 347 5667 67 566
Next day 345 234 453 69
Hmmm - I don't see too much of your own in your post; you even copied the incorrect $A output that I now corrected in my original post #10.
Howsoever, try
HD="Date"
DT="$(/bin/date "+%Y-%m-%d")"
FN="App_log_${DT}_server"
ON="output/path/file.txt"
SRC="Execution Complete "
for num in $servernums
do HD="$HD server${num}"
TMP=$(grep "$SRC" $FN$num|wc -l)
DT="$DT $TMP"
(( TOT += TMP ))
done
[ ! -f "$ON" ] && echo $HD Total > "$ON"
echo $DT $TOT >> "$ON"