[SOLVED] bash script modification help relating to linking html files for download
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
bash script modification help relating to linking html files for download
Hi.
I have a bash script that create a .html file that list all the files from a specific folder showing the date, the quantity of files in that folder, their titles, order numbers, ect...
Then that script copies that .html file to my Apache server.
I want to modify that script or may be the resulting .html file in order to link those files for download.
I know how to link a line to a file (one by one is not an option) or i could make the directory content downloadable but i rather modify the script instead, is it possible and how should i do it? Thank You.
Here is a sample of that script:
Code:
#!/bin/bash
# y
cd /media/norm/83644822B578E/x/y/
date > ty.html
echo "<hr>" >> ty.html
echo "y<br />" >> ty.html
number=`ls *.txt | wc -l`
echo "Their is $number y in this folder.<br />" >> ty.html
echo "<hr>" >> ty.html
count=0
for i in *txt ; do
#echo item: $i
((count+=1))
echo "# $count<br />" >> ty.html
echo $i "<br>" >> ty.html
done
cp /media/norm/83644822B578E/x/y/ty.html /var/www/html/list
have you thought about maybe tar'ing all of the files then attach that to your download link to save time having to click each and every link to get the entire contents?
your loop in the script should be controlled by your total count or EOF. or a while loop even.
Code:
#!/bin/bash
script_dir=/holding_dir_for_file
search_dir=/where_ever
count=0
#header code and date time stamp echo'ed in here,
#then add links here
while read f ; do
{
echo "<a href="\"$f\"">$f</a>" >> ty.html
((count++))
}
done <<<"$(find "$search_dir" -type f )"
echo " total files : $count " >> ty.html
#then finalizing code to end your html file suitable for hosting here
cp or mv $script_dir/ty.html /var/www/html/list
ty.html is being created with the folder content listed in it, and all lines show a link in "blue" but all the line point to where the new ty.html is located (in var/www/html/list) not where the the .txt files are located
(/media/norm/83644822B578E/x/y)
ty.html is being created with the folder content listed in it, and all lines show a link in "blue" but all the line point to where the new ty.html is located (in var/www/html/list) not where the the .txt files are located
(/media/norm/83644822B578E/x/y)
You need to construct the href value to be correct...pre-pend the path to the contents of the href= string:
NOTE: Linking to the files will still require a visitor to right-click and select the appropriate item to download the file (On Firefox it's "Save link as...")
I'll need to remember how to make the link be a "download link"...I know I've done that...
Ahh (DDG is my friend)
As per your first reply it listed the name of the .txt properly but they link where the ty.html is located.
And as per your second reply all the .txt are called "$1" in the ty.html and still link to the ty.html location.
NOTE: Linking to the files will still require a visitor to right-click and select the appropriate item to download the file (On Firefox it's "Save link as...")
I'll need to remember how to make the link be a "download link"...I know I've done that...
NOTE: Linking to the files will still require a visitor to right-click and select the appropriate item to download the file (On Firefox it's "Save link as...")
I'll need to remember how to make the link be a "download link"...I know I've done that...
Ahh (DDG is my friend)
I thought it work perfect then i realised that some of these files have blank space in there name, so the link does not work.
Is there some line i can add to the script for it to disregarded the blank space. Otherwise it works nice.
Thank You
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.