LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-31-2008, 07:18 AM   #1
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Rep: Reputation: 15
Question 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.
 
Old 05-31-2008, 07:49 AM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,244

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
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
 
Old 06-02-2008, 03:25 AM   #3
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Original Poster
Rep: Reputation: 15
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>
 
Old 06-03-2008, 08:59 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,244

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
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
 
Old 06-04-2008, 02:20 AM   #5
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Original Poster
Rep: Reputation: 15
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}
 
Old 06-04-2008, 07:23 AM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,244

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
Quote:
Originally Posted by cghcgh View Post
${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
 
Old 06-05-2008, 10:07 PM   #7
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Original Poster
Rep: Reputation: 15
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?
 
Old 06-05-2008, 10:54 PM   #8
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,244

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
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
 
Old 06-10-2008, 02:18 AM   #9
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Original Poster
Rep: Reputation: 15
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.!
 
Old 06-10-2008, 03:11 AM   #10
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
ls -t

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

ls -t |head -2

for the top 2
 
  


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
awk/perl script for extract data mruknown1 Programming 3 09-11-2007 10:19 AM
awk/perl script for extract data mruknown1 Linux - Newbie 2 09-11-2007 05:42 AM
How to extract information from a large data pool with AWK script? underskinned Programming 2 11-23-2006 10:26 PM
LXer: Extract data from the Internet with Web scraping LXer Syndicated Linux News 0 03-29-2006 01:55 PM


All times are GMT -5. The time now is 12:17 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration