Register
It is currently Fri Nov 21, 2014 2:12 pm

"CMS" with bash


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Tue Apr 15, 2008 9:38 pm   

Joined: Tue Apr 15, 2008 9:24 pm
Posts: 1
This probably isn't the best way to do this, but it sort of works.

Code:
echo "#CMS.sh"
echo -n "Title of post: "
read title
echo -n "Text: "
read text
echo "<i>" >>date
date >>date
echo "</i>" >>date
echo "<p>" >>new.html
cat date >>new.html
echo "</p>" >>new.html
echo "...................." >>new.html
echo "<h1>"$title"</h1>" >>new.html
echo $text >>new.html
cat index.html >>old.html
cat old.html >>index.html
cat new.html >>index.html
rm -f new.html old.html date


what I want to do is add new text to an html file at the top of the page.

The following is what I get when I run it.

Quote:
Tue Apr 15 22:34:48 CDT 2008
....................
old title
old text

Tue Apr 15 22:34:53 CDT 2008
....................
new title
new text

Tue Apr 15 22:34:48 CDT 2008
....................
old title
old text


I'm trying to get it to look like

<new post>
<old post>

Thanks in advanced for any help.


Top
 Profile  
 PostPosted: Tue Sep 09, 2008 11:16 am   

Joined: Tue Feb 06, 2007 2:25 pm
Posts: 13
Location: Liverpewl
actually, I've recently done something quite similar...
http://www.csc.liv.ac.uk/~cs6rlw/projects.html#scms
There's a 'blog' part with an atom feed. Maybe you could scavenge some of that?

New version out soon with pluggable modules (once the uni login servers come back up).
If you use it, give credit ;)


Top
 Profile  
 PostPosted: Wed Sep 10, 2008 10:48 am   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
You could also reword your current one to be much simpler. Use `read -p' instead of `echo -n; read', and use heredocs with cat

Code:
cat > file.html <<_EOF
<p>foo</p>
<p>$bar></p>
_EOF


Top
 Profile  
 PostPosted: Wed Sep 10, 2008 10:55 am   

Joined: Tue Feb 06, 2007 2:25 pm
Posts: 13
Location: Liverpewl
re-reading the original question. The reason you get the new stuff after the old is because you're adding it to the file after the old one.
Code:
cat old.html >>index.html
cat new.html >>index.html
rm -f new.html old.html date


something like:
Code:
mv index.html old.html
cat new.html > index.html
cat old.html >> index.html
rm -f old.html


Note that this approach will be problematic once you actually start outputting html, as the html/body etc tags will get messed up.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP