LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   run script to extract data to put to web (https://www.linuxquestions.org/questions/programming-9/run-script-to-extract-data-to-put-to-web-646029/)

cghcgh 05-31-2008 06:18 AM

run script to extract data to put to web
 
Hi,

I would like a question. I will be doing script that will extract data/logs from other servers. What will be the best to put it in html so that i can display in apache?

Do i actually build up the html while the data is being collected? ie everything runs from a script?

or should i extract the data, then have another script to sort out the relevant information to build a page?

Sorry that i dun have much knowledge on this? Pls kindly assist. Thanks.

jlinkels 05-31-2008 06:49 AM

Follow something which is very common. Build the web page with PHP. If you have a lot of data and/or you want to see history, put it in a MySQL database and retrieve it from there. If the information is not much, you can integrate data retrieval and page building in one PHP script. Even if you use separate scripting to retrieve data and put it in MySQL, you can use PHP as command line script.

I started using this approach 1.5 years ago and got something up and running in one weekend. Good explanation and plenty of examples on www.php.net

jlinkels

cghcgh 06-02-2008 02:25 AM

hi..i managed to incorporate the building of the website into the script. Currently, i'm facing a little issue over here. i can retrieve the log over( using sftp, then rename it to html ) but in it contains < > symbols....which the contents in it is important and i want to retain it. or is there any way to display the .log directly onto the page?

Some example

<xxxx.xxxx: Error:Sat Sep 08 11:35:55 2007>
Transport node error on node 0x1233
<END>

jlinkels 06-03-2008 07:59 PM

Using sed or so, replace all '<' '>' and with ampersand#060; and ampersand#060; respectively. Ampersand is the '&' symbol but I cannot write the string here, because the browser translates that to < and >. You also might try to use <pre> and </pre> labels around your log part but I am not sure that works.

jlinkels

cghcgh 06-04-2008 01:20 AM

great jlinkels.....i can do it..

another question though.....

i have a variable call A
A="aaa"

i want to append string "bbb" to the end of A

can i do this?
${A}=${A}bbb ?
or echo "bbb" >> ${A}
or cat "bbb" >> ${A}

jlinkels 06-04-2008 06:23 AM

Quote:

Originally Posted by cghcgh (Post 3174131)
${A}=${A}bbb ?

That is correct Bash syntax. It yields 'aaabbb' for $B. The other two are syntactically correct, but do not change $B. If you use
Code:

echo "bbb" >> ${A}
you would echo the 'bbb' string into a file called 'aaa'.
If you use
Code:

cat "bbb" >> ${A}
you would echo the contents of the file 'bbb' string into a file called 'aaa'.

You can try such constructs easily in a console, and verify that they work.

Note that in my previous post I had a typo concerning the code for '>' That should be ampersand#062; instead of ampersand#060; I wrote the same string twice.

jlinkels

cghcgh 06-05-2008 09:07 PM

hi jlinkels, still having some errors on my side.

Try to do a
${A}=${A}bbb ....but it seems that it cant pass there's a problem with the 1st ${A}.
what i do not is create a tmp file and echo the messages in there which i think isn't efficient

2nd
i try to sed < for & #60 and > for & #62 but it still show as <#060 and >#062


any idea?

jlinkels 06-05-2008 09:54 PM

Sorry, it is A=${A}bbb
No curly braces around the first A, overlooked that.

ampersand#062;
The correct sequence is:
ampersand_sharp_zero_six_two_semicolon

I think you forgot the semicolon. No spaces or underscores between the characters.

jlinkels

cghcgh 06-10-2008 01:18 AM

i got that now.. thanks jlinkels. Got another question though...
i have a log location where it keeps the log file as below

-rw-r--r-- 1 root root 6721 Dec 1 2007 LOG_dts2007_12_01
-rw-r--r-- 1 root root 6721 Feb 23 14:03 LOG_dts2008_02_23
-rw-r--r-- 1 root root 140 Mar 8 12:30 LOG_dts2008_03_08
-rw-r--r-- 1 root root 140 May 3 09:12 LOG_dts2008_05_03
-rw-r--r-- 1 root root 6869 May 31 11:41 LOG_dts2008_05_31


How do i grep the filename of the latest file or 2 of the latest file? the log doesnt generate everyday. Thanks.!

chrism01 06-10-2008 02:11 AM

ls -t

should sort the files in last modified time order, newest at the top

ls -t |head -2

for the top 2


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