How to create an excel worksheet throught a shell script? - html

I'm trying to create a shell script that creates an output file with html content & xml content but my goal is open this file as an excel workbook/file (xls format).
This is a part of the code:
Log INF "Creating the first excel file: ${FICHERO_OUT}"
echo "<html>" >> ${DIR_OUT}/${FICHERO_OUT}
echo "<style>
.table_main {
border: 1px solid black;
border-top-style: ridge;
border-bottom-style: ridge;
border-left-style: ridge;
border-right-style: ridge;
border-color: black;
}
</style>" >> ${DIR_OUT}/${FICHERO_OUT}
echo " <body>" >> ${DIR_OUT}/${FICHERO_OUT}
echo '<table>' >> ${DIR_OUT}/${FICHERO_OUT}
echo '<th class="table_main" bgcolor="##FFBF00">ERROR</th>' >> ${DIR_OUT}/${FICHERO_OUT}
echo '<th class="table_main" bgcolor="##FFBF00" >DESCRIPTION</th>' >> ${DIR_OUT}/${FICHERO_OUT}
echo "<tr>" >> ${DIR_OUT}/${FICHERO_OUT}
echo "<td>0</td>" >> ${DIR_OUT}/${FICHERO_OUT}
echo "<td>DES</td>" >> ${DIR_OUT}/${FICHERO_OUT}
echo "</tr>" >> ${DIR_OUT}/${FICHERO_OUT}
echo '</table>' >> ${DIR_OUT}/${FICHERO_OUT}
echo " </body>" >> ${DIR_OUT}/${FICHERO_OUT}
echo "</html>" >> ${DIR_OUT}/${FICHERO_OUT}`
This part of the code works fine, but when I try to modify the Worksheet name, I can't. I try to do it with the next code:
echo "<?xml version="1.0"?>" >> ${DIR_OUT}/${FICHERO_OUT}
echo "<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"" >> ${DIR_OUT}/${FICHERO_OUT}
echo "xmlns:o="urn:schemas-microsoft-com:office:office"" >> ${DIR_OUT}/${FICHERO_OUT}
echo "xmlns:x="urn:schemas-microsoft-com:office:excel"" >> ${DIR_OUT}/${FICHERO_OUT}
echo "xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"" >> ${DIR_OUT}/${FICHERO_OUT}
echo "xmlns:html="http://www.w3.org/TR/REC-html40">" >> ${DIR_OUT}/${FICHERO_OUT}
echo "<Worksheet ss:Name="Student Data">" >> ${DIR_OUT}/${FICHERO_OUT}
echo "<table>" >> ${DIR_OUT}/${FICHERO_OUT}
....
I wrote here the HTML code I mentioned before.
....
echo "</table>" >> ${DIR_OUT}/${FICHERO_OUT}
echo "</Worksheet>" >> ${DIR_OUT}/${FICHERO_OUT}
echo "</Workbook>" >> ${DIR_OUT}/${FICHERO_OUT}
Please, could someone help here? Any suggestion to modify the worksheet name? Any alternative?

When you want to open the file with Excel, generate a .csv file.
When you start the .csv file with a line SEP=x, the character x will be used between fields.

Finally, I've solved it. I did it, using only xml code and adding "sqlplus querys + spool".
Thank you very much for your support.
Best Regards,

Related

Bash shell script html css

while read row do
echo "<tr>" >> $file
for valore in $row
do
echo "<td>$valore</td>" >> $file
done
echo "</tr>" >> $file
done < alunni.txt
echo "</table>" >> $file
When I execute this fraction of code it gives me this error:
./table_html.csv: line 36: syntax error near unexpected token `echo'
./table_html.csv: line 36: ` echo "<td>$valore</td>" >> $file'
How do I fix it?
I'm not very good with shell scripts, that's why I can not think of anything else.
(Ah I was working on this when the alarm for the oven went off) what I wanted to say was it's just the "do" in the wrong place after the while. So here's your code restated (with a file="filename" added to get it working):
file="test2.html"
while read row
do
echo "<tr>" >> $file
for valore in $row
do
echo "<td>$valore</td>" >> $file
done
echo "</tr>" >> $file
done < alunni.txt
echo "</table>" >> $file
So it was just a line break before the do is all you needed :-)

convert text file to html ouput so that data can be printed in table format

I have a text file which has 3 values separated by :
25-08-2019_19.00.00 : Port port1 of URL http://ip1:port1/ is NOT OPEN : Zoom1
25-08-2019_19.00.00 : Port port2 of URL http://ip2:port2/ is NOT OPEN : MP
and so on.
I want to print the output to a html type tabular format file, which has 3 headings, date, output and system and corresponding data in 3 columns.
I tried below code, but it is not putting data to table format.
#! /bin/bash
if [ $# -eq 0 ] ; then
echo "USAGE: $(basename $0) file1 file2 file3 ..."
exit 1
fi
for file in $* ; do
html=$(echo $file | sed 's/\.txt$/\.html/i')
echo "<html>" >> $html
echo "<style type="text/css">
table, th, td {
border: 1px solid black;
}
</style>" >> $html
echo " <body>" >> $html
echo '<table>' >> $htm
echo '<th>HEADING1</th>' >> $html
echo '<th>HEADING2</th>' >> $html
echo '<th>HEADING3</th>' >> $html
while IFS=':' read -ra line ; do
echo "<tr>" >> $html
for i in "${line[#]}"; do
echo "<td>$i</td>" >> $html
# echo "<td>$i</td>" >> $html
done
echo "</tr>" >> $html
done < $file
echo '</table>'
echo " </body>" >> $html
echo "</html>" >> $html
done
If you can, please consider awk:
awk -F' : ' '
BEGIN{
print "<html><style type=\"text/css\">table, th, td {border: 1px solid black;}</style><body><table><th>HEADING1</th><th>HEADING2</th><th>HEADING3</th>"
}
{
print "<tr>"
for(i=1;i<=NF;i++)
print "<td>" $i "</td>"
print "</tr>"
}
END{
print "</table></body></html>"
}
' input_file > output.html
The BEGIN and END statement fills the static html tags.
The middle statement fills one line of the array according to each input file line by adding <tr> for each line and <td> for each field.

CGI : How to put Gnuplot command in my bash script?

I am setting up a bash/html CGI that will allow me to generate graphs with GnuPlot.
For this, I have two CGI pages in bash/html:
The first page contains a simple "generate" button that opens a new page and executes my gnuplot script, and a listbox that will have been previously filled with the names of different clusters.
The second page that is opened via the "generate" button displays my graph.
My question is: how do I put gnuplot commands in my CGI page in bash/html ?
Here is the code of my first page that allows me to choose the cluster that interests me :
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo '
<html>
<head>
<meta http-equiv="Content-Type" content="test/html"; charset=UTF-8">
<title> CLUSTER GRAPH </title>
<h1> Cluster Graph <font size=3> [ Index ] </font> </h1>
<hr size="4" color="blue">
</head>
<body>
<p> Choose a Cluster and press the button to generate the graph ! </p>'
Cluster_Name=$(cat ClusterFullList.csv | awk '{print $3}' | sort |uniq)
echo "<form action="Script_test.sh" method="post">"
echo "<select name="CLUSTER">"
echo "$Cluster_Name" | while read CLUSTER; do
echo " <option value="$CLUSTER">$CLUSTER</option>"
done
echo "</select>"
echo"<br><br>"
echo "<input type="submit" value="Generate">"
echo "</form>"
echo '
</body>
</html>
'
Here is the code of my second page on which my graph should appear:
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "
<html>
<head>
<title> CLUSTER GRAPH </title>
<h1> Cluster Graph <font size=3> [ Index ]</font></h1>
<hr size="4" color="blue">
</head>
<body>
<img src="$test.png">
<PRE>"
read a
test=`echo $a | cut -d'=' -f2`
echo "$test"
echo " f(w) = (strlen(w) > 10 ? word(w, 1) . "\n" . word(w, 2) : w) " >> gnuplot_script_test.txt
echo " set title $test " >> gnuplot_script_test.txt
echo " set terminal png truecolor size 960, 720 " >> gnuplot_script_test.txt
echo ' set output "$test.png" ' >> gnuplot_script_test.txt
echo " set bmargin at screen 0.1 " >> gnuplot_script_test.txt
echo " set key top center " >> gnuplot_script_test.txt
echo " set grid " >> gnuplot_script_test.txt
echo " set style data histograms " >> gnuplot_script_test.txt
echo " set style fill solid 1.00 border -1 " >> gnuplot_script_test.txt
echo " set boxwidth 0.7 relative " >> gnuplot_script_test.txt
echo " set yrange [0:] " >> gnuplot_script_test.txt
echo " set format y "%g%%" " >> gnuplot_script_test.txt
echo " set datafile separator "," " >> gnuplot_script_test.txt
echo ' plot "/var/www/cgi-bin/CLUSTER_1.txt" using 2:xtic(f(stringcolumn(1))) title " CPU consumption (%) ", '' using 3 title " RAM consumption (%)", '' using 0:($2+1):(sprintf("%g%%",$2)) with labels notitle, '' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle ' >> gnuplot_script_test.txt
gnuplot gnuplot_script_test.txt
rm gnuoplot_script_test.txt
echo "
</PRE>
</body>
</html>
"
The idea is :
The commands:
read a
test=`echo $a | cut -d'=' -f2`
echo "$test"
Allow me to retrieve my query string which is the name of the cluster I am interested in (cluster name which is in the list box of my first page)
I execute the gnuplots commands and send them each time in the file "gnuplot_script_test.txt", then I execute it via the command :
gnuplot gnuplot_script_test.txt
Then the txt file deletes itself via the command :
rm gnuplot_script_test.txt
I would like to make sure that the name of the cluster I retrieve via my query string, I can put it in my gnuplot commands. To do this, I put my variable "$test" (which contains the name of my cluster) in the lines :
echo" set title "$test""
To put the name of my cluster in my title
echo ' set output "$test.png" '
To give my png the name of my cluster
But, when I choose my cluster on my first page, that I click on generate, the name of my cluster appears well on my second page, but the image is not generated...
Can you tell me why ?
Thank you !
You are using $test variable before you set it up.
You can find helpful heredoc http://tldp.org/LDP/abs/html/here-docs.html
Then you can do e.g.:
gnuplot <<EOF_GNUPLOT
# your gnuplot code here - e.g.:
reset
set term png truecolor enhanced size 1050,1050
set xtics out
# ...
EOF_GNUPLOT

How to send a html file using mails in shell script?

I want to store my matrix's data in a html file and send a email in outlook ,my code looks as follows:
printf "<!DOCTYPE html>"
printf "<html>"
printf "<head>"
printf "<style>"
printf "</style>"
printf "</head>"
printf "<body>"
printf "<table>"
printf "<tr>"
printf "<th>Total</th>"
printf "<th>StillFail</th>"
printf "<th>Pass</th>"
printf "<th>ScriptError</th>"
printf "<th>APIName</th>"
printf "</tr>"
printf "<tr>"
echo
for ((j=1;j<=num_rows;j++)) do
printf "<tr>"
for ((i=1;i<=num_columns;i++)) do
printf "<td>"
printf "${matrix[$j,$i]}"
printf "</td>"
printf "</tr>"
done
echo
done
printf "</tr>"
printf "</table>"
printf "</body>"
printf "</html>"
#mailx -a 'Content-Type: html' -s "my subject" test#example.com < output.html
mailx -s "TESTING MAIL"</home/test/example/output.html "test#example.com"
I want my output as a well aligned table. Can someone help me on this? TIA
You need to append content-type in header it can be done with -a flag in mailx
comment your last line and try this
mailx -a 'Content-Type: text/html' -s "Test MAIL" test#example.com</home/test/example/output.html
Edit :
As per the OP End error : content-type:texthtml no such file or
directory
To install mailutils in mac
Press Command+Space and type Terminal and press enter/return key.
Run in Terminal app:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
and press enter/return key. Wait for the command to finish.
Run:
brew install mailutils
reference : http://macappstore.org/mailutils/
Maybe you can use this for a base:
(
echo "To: ADRESSES"
echo "Subject: SUBJECT"
echo "Content-Type: text/html"
echo
echo "HTML code"
) | /usr/sbin/sendmail -F "NameOfSender" -t

How to send using with attachment and html body using mailx [duplicate]

This question already has answers here:
Mailx send html message [duplicate]
(6 answers)
Closed 4 years ago.
I want to send an e-mail using mailx which has an attachment and HTML code on the body.
Setting the Content-type to "text/html" mail comes with file binary content on the body instead of attached.
echo "" >> $MAILFILE
echo "<HTML>" >> $MAILFILE
echo "<HEAD>" >> $MAILFILE
echo "</HEAD>" >> $MAILFILE
echo "<BODY>" >> $MAILFILE
echo "<table border="1">" >>$MAILFILE
echo "<tr bgcolor=#C0C0C0>" >>$MAILFILE
echo "<td><b>OUTAGE</b></td>" >>$MAILFILE
echo "<td>$OUTAGE_COUNT</td>" >>$MAILFILE
echo "</tr> </table><br>" >>$MAILFILE
echo "</table>" >> $MAILFILE
echo "</BODY></HTML>" >> $MAILFILE
(uuencode outage.zip outage.zip;cat $MAILFILE) | mailx -s "Outage Payments Status
Content-type: text/html" $distro -- -f ${EMAIL_FROM}
Result - Body's email:
begin 644 outage.zip M4$L#!!0````(`,:$(T5RYN"0#P```.D#```3`!4`;W5T86=E7W!A>6UE;G1S M+F-S=E54"0`#)&X'5"1N!U15>`0`.GX1#5-0#`(3A5$P"D;!,`5<&%Y;65N=',N8W-V550%``,D;#=457#``%!+!08``````0`!`$X```!5 %```````` ` end
Instead use sendmail as follows :
#!/usr/bin/ksh
export MAILTO="spam#ebay.com"
export SUBJECT="Mail Subject"
export BODY="/tmp/email_body.html"
export ATTACH="/tmp/attachment.txt"
(
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
echo
echo '---q1w2e3r4t5'
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $BODY
echo '---q1w2e3r4t5'
echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
uuencode -m $ATTACH $(basename $ATTACH)
echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO