LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-07-2013, 02:57 AM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Rep: Reputation: 0
Output not visible in html format?


Hi Guys,

I have a small piece of code which ideally "should" give output in html format but it is not.

What could be the probable issue?

Here is the code.


Code:
#!/bin/sh

set -xv
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"

DATE=`date -u`

# Print beginning of webpage
function html_header
{
cat <<END
        <html>
         <head><title>${1}</title></head>
         <body>
         <h3>${1}</h3>
         <!-- Table of Contents links -->
         <p>
         <a href='#rpmversion'>RPM Versions</a>
         <a href='#processes'>Processes</a>
         </p>
END
}

function html_footer
{

cat <<abc
</body>
</html>
abc

}

function html_title
{
echo "<h3><a name='#${2}'>$1</a></h3>"
}

function rpm_versions
{
html_title "RPM Versions" "rpmversion"
echo "<pre>"
rpm -qa|sort
echo "</pre>"
}

function get_allprocs
{
html_title "All Running Processes" "processes"
ps -fu ${USER}
}

html_header "Report Summary for ${DATE}" >> temp2.html 
rpm_versions >> temp2.html
get_allprocs >> temp2.html
html_footer >> temp2.html

cat temp2.html| mailx -s "Report" test@testme.com
 
Old 05-07-2013, 04:47 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Change the first line to use bash instead of sh and run it and capture the the output and stderr. The 'set -xv' will show what's going on
Code:
./myscript.sh >script.log 2>&1
 
1 members found this post helpful.
Old 05-07-2013, 05:26 AM   #3
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
@chrism01

Can you please advise what made you to think to change the execution of shell from sh to bash?

I executed as advised but cannot think of anything obvious
 
Old 05-07-2013, 05:29 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Well, basically, bash is more capable than sh; eg see the many posts by David_the_H.
Its up to you, but I'd go with bash where its available (on Linux).
Anyway, that's a minor point.

If you ran the code, the set cmd should have helped you to debug.
If you're really stuck, you can post it.
 
1 members found this post helpful.
Old 05-07-2013, 06:02 AM   #5
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
Thanks Chris. Well I don't know where to start. I have no idea whatsoever why the heck this sh1t is not working.
 
Old 05-07-2013, 06:04 AM   #6
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
If you try the same code on your box does it work?
 
Old 05-07-2013, 06:23 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
What makes you think it doesn't?
Have you tried it?

Why not use echo for all output instead of cat + here-docs.

Why not cut it down to just eg report header.
ie Break it down into smallest possible bits and test each one, then gradually add them together.
 
Old 05-07-2013, 09:37 AM   #8
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
I did try but output is not in html format. One good suggestion is about dividing it into small chunks which I would certainly try it out
 
Old 05-07-2013, 11:58 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
I would ask the same question as chrism01, What is the code doing / not doing that tells you it has not worked?

I would also query the first 3 echo lines of the script? Any particular need to have this information delivered to the screen?

I would probably go one of 2 ways, assuming set -xv doesn't help:

1. Start with one function and build up to the others but output the smallest amount of html and build

2. Go the opposite direction and place all the html in 1 here document and slowly strip out individual pieces


Looking at the code, unless this is part of something much bigger, generally the idea of a function is to reduce repetition of code.
It would appear none of your functions are likely to ever be repeated ... just a thought.
 
Old 05-07-2013, 08:54 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
I'd also add (just in case you've got the wrong idea about html), that the code above will merely produce TEXT file with HTML markup.
If you want to see that as a web-page, you'd have to read it via a browser, either directly (File->Open File ..) or put it in the Document dir of a webserver (eg Apache).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SVN : - some mails are coming in plain format (html coding) & some in html format deepakdeore2004 Linux - General 0 05-06-2010 02:54 AM
Best video format for YouTube upload and can Recordmydesktop output that format? linus72 Linux - Software 6 12-21-2009 04:53 PM
[SOLVED] Getting xdebug 2.0.5 switch text output to html output lhorace Linux - Server 1 11-01-2009 06:23 PM
mails are not being sent in html format makalas Linux - Newbie 3 05-08-2007 07:09 AM
PERL -- Out to html format maseby Programming 2 04-06-2006 12:05 AM


All times are GMT -5. The time now is 06:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration