Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 4872 Location: Blue Springs, MO
|
Posted: Sun 19 Dec 2010, 17:44 Post subject:
Web Programming |
|
I intentionally did not specify html programming in the topic, since web programming can take several forms.
Please post your web programming tip, tricks or questions here.
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4872 Location: Blue Springs, MO
|
Posted: Sun 19 Dec 2010, 17:45 Post subject:
|
|
Here is a script that will generate an html index of directories and files.
Code: | #!/bin/sh
# $1 is a directory to index as html
cd $1;
for x in *; do [ -d "$x" ] && D=$D"<li><a href=\"$x/\">$x/</a></li>" || F=$F"<li><a href=\"$x\">$x</a></li>"; done
echo "<html><head><title>index of $1</title></head><body><p><b>index of $1</b></p><p>directories:</p><ul><li><a href=\"../\">[parent directory]</a></li>$D</ul><p>files:</p><ul>$F</ul></body></html>" >$1/index.html |
there is a C version of this script here:
http://www.mathopd.org/dist/dir_cgi.c.txt
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
Last edited by technosaurus on Sun 19 Dec 2010, 21:50; edited 1 time in total
|
Back to top
|
|
 |
trapster

Joined: 28 Nov 2005 Posts: 2119 Location: Maine, USA
|
Posted: Sun 19 Dec 2010, 18:09 Post subject:
|
|
Not working well with spaces in file names.
_________________ trapster
Maine, USA
Asus eeepc 1005HA PU1X-BK
Frugal install: Slacko
Currently using full install: DebianDog
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Sun 19 Dec 2010, 19:46 Post subject:
|
|
Hey trapster
Quote: | Not working well with spaces in file names. |
this will auto fix /heal all folders and files with spaces or symbols and convert them to underscore "_"
just place it in the folder with the bad names and run it
all is automatic
Joe
Code: |
#!/bin/bash
# Joe Arose version 1.05
# sana_auto = auto find and repair
# sana = sanitize these =;:"`<>,!@#$?%^*&(){}[]
# sana = sana sana colita de rana "for the spanish translation"
# drag N drop rename files that have been badly named
# to a corrected format with underscores
# many bad characters get deleted
# programs will not function correctly with spaces placed in the name
# note that permissions are preseved !
rm -f /tmp/sanitized
rm -f /tmp/borked_name
rm -f /tmp/fix_borked_names.txt
#this is faster fix directories first later it will fix the files
find $pwd -type d | tr " " "?" | tr '=;"`<>,!@#$?%^*&(){}[]' '?'| grep '?' >>/tmp/fix_borked_names.txt
#so you have a list of changed files that have ???
cp /tmp/fix_borked_names.txt /tmp/fix_borked_names_dir$$
##special function to clean everything
for pkg in `cat /tmp/fix_borked_names.txt` ;do
echo "$pkg" | tr -d '=;`"<>,?!@#$%^*&(){}[]' |tr -s ' ' '_*' >/tmp/sanitized
echo "$pkg" | tr " " "?" | tr '=;"`<>,!@#$?%^*&(){}[]' '?' >/tmp/borked_name
rename_bork=`cat /tmp/borked_name`
echo "$rename_bork"
for_cleaned=`cat /tmp/sanitized`
echo "$for_cleaned"
mv $rename_bork $for_cleaned
Xdialog --title "working on directories" \
--infobox "\nConversion to $for_cleaned has finished.\n" 0 0 1000
done
Xdialog --title "Complete" \
--infobox "\n Auto conversion folders finished.\n" 0 0 3000
#-----------------------------
# fix all the files now
#----------------------------
rm -f /tmp/sanitized
rm -f /tmp/borked_name
rm -f /tmp/fix_borked_names.txt
find $pwd -type f | tr " " "?" | tr '=;"`<>,!@#$?%^*&(){}[]' '?'| grep '?' >>/tmp/fix_borked_names.txt
#so you have a list of changed files that have ???
cp /tmp/fix_borked_names.txt /tmp/fix_borked_names_files$$
##special function to clean everything
for pkg in `cat /tmp/fix_borked_names.txt` ;do
echo "$pkg" | tr -d '=;`"<>,?!@#$%^*&(){}[]' |tr -s ' ' '_*' >/tmp/sanitized
echo "$pkg" | tr " " "?" | tr '=;"`<>,!@#$?%^*&(){}[]' '?' >/tmp/borked_name
rename_bork=`cat /tmp/borked_name`
echo "$rename_bork"
for_cleaned=`cat /tmp/sanitized`
echo "$for_cleaned"
mv $rename_bork $for_cleaned
Xdialog --title "working on files" \
--infobox "\nConversion to $for_cleaned has finished.\n" 0 0 1000
done
Xdialog --title "Complete" \
--infobox "\n Auto conversion files finished.\n" 0 0 3000
|
Last edited by big_bass on Tue 21 Dec 2010, 00:33; edited 2 times in total
|
Back to top
|
|
 |
trapster

Joined: 28 Nov 2005 Posts: 2119 Location: Maine, USA
|
Posted: Sun 19 Dec 2010, 20:04 Post subject:
|
|
big_bass -
Thanks for the offer and I will save this for future use but I have 6,000 songs + movies already running on my server and I don't want to mess with the filenames.
I do use "tree" to create an html file index.
ie:
Code: | tree -a -H /mnt/home/music > /mnt/home/music/index.html |
Works a treat.
_________________ trapster
Maine, USA
Asus eeepc 1005HA PU1X-BK
Frugal install: Slacko
Currently using full install: DebianDog
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Sun 19 Dec 2010, 20:56 Post subject:
|
|
Hey technosaurus ,trapster
well here is a real simple basic index maker and easy to edit
for anyone to hack at
Code: |
#!/bin/sh
#code from Joe Arose big_bass built for special use
# generate a custom index
# drag N drop a folder on the script
#with the end goal of easily making the correct formatting
#simple and clean
#as just the URL's then generate a new index
#/root/new_index_list #this is the index generated
#---------------index maker--------------------------------
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of </title>
</head>
<body>
<h1>Index of new_index_list</h1>
<pre><img src="/usr/local/lib/X11/pixmaps/archive48.png" alt="Icon "> <a href="?C=N;O=D">Name</a>' >/root/new_index_list
for i in `find "$@"/*`
do echo "<"a href="$i"">"$i"<"/a">" >>/root/new_index_list
done
echo '<hr></pre>
<address>Apache Server at distro.ibiblio.org Port 80</address>
</body></html>' >>/root/new_index_list
#you can edit this if you have seamonkey
#gtkmoz /root/new_index_list
/usr/lib/firefox/firefox /root/new_index_list
|
|
Back to top
|
|
 |
abushcrafter

Joined: 30 Oct 2009 Posts: 1438 Location: England
|
Posted: Sun 19 Dec 2010, 21:05 Post subject:
|
|
http://www.catb.org/~esr/imgsizer/
Quote: | This tool auto-generates or corrects WIDTH and HEIGHT parameters into HTML IMG tags, making page loading faster. |
_________________ adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4872 Location: Blue Springs, MO
|
Posted: Sun 19 Dec 2010, 21:37 Post subject:
|
|
Use this to remove spaces:
Code: | for x in *; do X="`echo $x|tr ' ' '_'`";[ "$x" != "$X" ] && mv "$x" "$X"; done |
I used * to fix the initial version too - so it should allow spaces when I repost it
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Mon 20 Dec 2010, 12:21 Post subject:
|
|
Hey technosaurus
I liked the visual output of the generated code you did nice job
It however was difficult to read the source code
I combined my code with yours to have both
the source and the output pretty
thanks for starting this thread
and posting your code
Joe
*this takes more lines of course but the byte count is still very low
EDIT filter for files so folder isnt made for directories also
Code: |
#!/bin/sh
# drag N drop html index maker
# "$@" is a directory to index as html
# technosaurus author
# big_bass improved generated source code readability
cd "$@"
#---------------------
# clean up old debugging files
#---------------------
rm -f "@"/index.html
rm -f /tmp/flist2
rm -f /tmp/dlist2
#---------------------
# generate the directory and file index
#---------------------
for x in *
do [ -d "$x" ] && echo "<li><a href=\"$x/\">$x/</a></li>" >> /tmp/dlist2
! [ -d "$x" ] && echo "<li><a href=\"$x\">$x</a></li>" >>/tmp/flist2
done
#---------------------
# Head make the html head
#---------------------
echo "<html><head><title>index of "$@"
</title></head><body><p><b>index of "$@"</b>
</p><p>directories:</p>
<ul><li><a href=\"../\">[parent directory]</a>">"$@"/index.html
#---------------------
# Body append the dynamic info for the index here the (directories )
#---------------------
echo "</li>" >>"$@"/index.html
cat /tmp/dlist2>>"$@"/index.html
echo "</ul>">>"$@"/index.html
#---------------------
# Body append the dynamic info for the index here the (files )
#---------------------
echo "<p>files:</p><ul>" >>"$@"/index.html
cat /tmp/flist2 >>"$@"/index.html
echo "</ul>" >>"$@"/index.html
#---------------------
#Close the html header
#---------------------
echo "</body></html>" >>"$@"/index.html
# remove new debugging files
#rm -f /tmp/flist2
#rm -f /tmp/dlist2
|
Last edited by big_bass on Mon 20 Dec 2010, 15:33; edited 4 times in total
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4872 Location: Blue Springs, MO
|
Posted: Mon 20 Dec 2010, 14:27 Post subject:
|
|
Normally I would do the same, but wanted the code to be as fast as possible in case it's used as a cgi script - thus only one loop, one check and one echo... but I could probably add some return characters and/or backslashes for readability without affecting the speed.
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
sc0ttman

Joined: 16 Sep 2009 Posts: 2768 Location: UK
|
Posted: Tue 21 Dec 2010, 11:25 Post subject:
|
|
TechGuruLive.com wrote: | Besides from using perl scripts, phpmyadmin and customized php pages, here is a quick way to fetch data from mysql database using shell script.
Just make sure you are currently running mysql from your box with existing database and table inside.
First, launch your favorite linux editor and create a bash script and paste the following bash codes inside and save.
Code: | #!/bin/bash
# july 03 2007 – vertito
# this script retrieves data from mysql using bash
dbase=`mysql -uMYSQLUSENAME -pMYSQLPASSWORD -e”use MYDATABASE; select * from MYTABLE where id = 1;”`
for data in $dbase ;
do
echo $data
done
echo Done.
#chmod 700 yourscript.sh
#./yourscript.sh
|
Works like a charm!
Dont forget to change the following wordings:
MYSQLUSERNAME = your mysql username access with your mysql server
MYSQLPASSWORD = your mysql password
MYDATABASE = your running mysql database name
MYTABLE = your selected table name |
_________________ Pkg, mdsh, Woofy, Akita, VLC-GTK, Search
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Wed 22 Dec 2010, 10:49 Post subject:
|
|
having code examples are great when they can be recycled
what is worth more than any code snippet in itself
is the educational value it has
if you can learn something from the code it is useful
In my opinion
good documentation is worth more than the original work itself
because it invites creativity and growth
Joe
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Wed 22 Dec 2010, 11:04 Post subject:
|
|
Hey technosaurus
I recycled the code some more to take a plain text file as input
I dont have direct access to the folder /files on the server to dragndrop the file to build the index
I had earlier written my own indexing for my packages
I was happy with it but the rendering of the page was slow
due to the images and so I decided to go simple and clean
and re do it
*I had written a way to auto generate package sizes and the dates
but that only works when you have all the files on your box
if you (or any one else )see(s) something you would change / improve let me know
if you take a look at the link http://www.puppy2.org/slaxer/
here is a simple new index waiting on improvements
thanks
Joe
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4872 Location: Blue Springs, MO
|
Posted: Wed 22 Dec 2010, 12:02 Post subject:
|
|
... good idea for adding file size
need to change this:
F=$F"<li><a href=\"$x\">$x</a></li>"; done
to something like this:
F=$F"<li><a href=\"$x\">$x</a> `du $x` kb</li>"; done
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Wed 22 Dec 2010, 14:21 Post subject:
|
|
I just made two strings
$datemodified
$size
here is only an example I dont use the echoes
and the package is "x"
just wanted to post a stand alone snippet
awk is nice to get exactly what you want from the output
and this also displays in MB or KB automatically
Code: |
# use any package for a test
package="/root/qemu-0.91-launchscript-SDL-1.29-i486-3_SLXR.txz"
datemodified=`ls -lh "$package" | awk '{ print $6 }'`
size=`ls -lh "$package" | awk '{ print $5 }'`
echo $datemodified
echo $size
|
Joe
|
Back to top
|
|
 |
|