Answer the question
In order to leave comments, you need to log in
How to generate html from bash?
Hello.
There are some reports, many reports. They add up to the following file structure:
/reports
|__Year
|__Month_1
| |__Day_1
| | |__report_1.html
| | |__report_2.html
| | |__report_n.html
| |__Day_2
| |__report.....
|__Month_2.......
etc.
It is necessary to collect html on the bashik with spoilers / nesting:
1st level - Year
2nd level - Month
3rd level - Day
reports
So far, we managed to pull all the files with paths through find, save them to a textbox.
We read the textbook line by line and extract from it the year, month, day
But then the dregs ....
#!/bin/bash
find reports/folder_1/folder_2/ -type f > links.txt
echo "Создаем body.html для PROD и добавляем details"
echo "<details>" > body.html
while read LINE;
do
echo "$LINE"
for l in $LINE
do
YEAR="$( cut -d '/' -f 4 <<< "$l" )"
echo $YEAR
if grep "$YEAR" body.html; then
echo $YEAR
else echo "
<summary>$YEAR</summary> <br>" >> body.html
fi
MONTH="$( cut -d '/' -f 5 <<< "$l" )"
echo $MONTH
if grep "$MONTH" body.html; then
echo $MONTH
else echo "<details>
<summary>$MONTH</summary> <br>" >> body.html
fi
DAY="$( cut -d '/' -f 6 <<< "$l" )"
echo $DAY
if grep "$DAY" body.html; then
echo $DAY
else echo "<details>
<summary>$DAY</summary> <br>" >> body.html
fi
DIRPATH=${LINE%/}
echo $DIRPATH
for file in $DIRPATH/*
do
NAME="$( cut -d '/' -f 7 <<< "$l" )"
echo $NAME
echo "<a href="$LINE" class="rep-btn">$NAME</a> <br>" >> body.html
done
echo "</details>" >>body.html
done
done < links.txt
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question