Html upload file to bash script


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Html upload file to bash script
# 1  
Old 03-01-2019
Html upload file to bash script

I am trying to upload a file to the server using bash script in html form.

Code:
<FORM NAME="FORM1" METHOD="post" enctype="multipart/form-data" ACTION="/cgi-bin/UPLOAD.sh">
  <INPUT type="file" name="DOCFILE" id="DOCFILE"
   accept=".jpg,.tif,.pdf">
</FORM>

How can I able to access the file in the script. I appreciate any example.
# 2  
Old 03-01-2019
Link:
Linux wget command help and examples

This is a simple beginner's explanation of using wget in bash. Please read the WHOLE page. wget is meant to get files from the internet to your computer. IF you are at work and behind security (Example: a proxy or a nat server) things may get more complicated. See if this meets your needs.
# 3  
Old 03-01-2019
You access the file in your form using a web server set up handle scripts with file extension .sh.

But frankly, no experienced web developer uses bash for processing HTTPD $_GET and $_POST requests (unless they have some tiny web site and are just playing around) because bash is not designed to handle HTTPD requests (like HTTP headers, cookies, and more) like other programming languages are.

If you are serious about learning web development, you should use a language build for processing HTTPD requests, like server-side Javascript, PHP, etc.
# 4  
Old 03-01-2019
Quote:
Originally Posted by jim mcnamara
Link:
Linux wget command help and examples

This is a simple beginner's explanation of using wget in bash. Please read the WHOLE page. wget is meant to get files from the internet to your computer. IF you are at work and behind security (Example: a proxy or a nat server) things may get more complicated. See if this meets your needs.
Web developers not use generally (or specifically) wget in HTTP form element action requests.

I have written 100s of HTML forms like the one above and the action is never wget.

wget is a command line tool, not a program run by a HTTPD request handler (a web server) .
# 5  
Old 03-01-2019
OBTW, if you insist on using bash as your web server CGI, then you can check out this:

Simple CGI and Apache examples on Ubuntu Linux - LinuxConfig.org

Quote:
CGI ( Common gateway Interface ) is an interface between Web client and the web server that runs your CGI script/program. CGI is a quite old and was largely superseded by different programing languages such as PHP, etc. However, it still can find its place in Linux system administrator's hands as a quick tool for system monitoring and administration via web browser. This article describes in step-by-step manner how to run basic CGI scripts with various programming languages and scripts using Apache web server on Ubuntu Linux.
FWIW, I disagree with the statement in the quote above " it still can find its place in Linux system administrator's hands as a quick tool for system monitoring and administration via web browser", because there is no place for using obsolete languages not designed for the web as a CGI when you have so many better choices (PHP, node.js, Python, etc).

I have been administering web servers "forever", and never once have I ever written or used a bash CGI like described in the link above. It's simply the wrong tool for the job.
# 6  
Old 03-01-2019
Quote:
Originally Posted by Naz
I am trying to upload a file to the server using bash script in html form.

Code:
<FORM NAME="FORM1" METHOD="post" enctype="multipart/form-data" ACTION="/cgi-bin/UPLOAD.sh">
  <INPUT type="file" name="DOCFILE" id="DOCFILE"
   accept=".jpg,.tif,.pdf">
</FORM>

How can I able to access the file in the script. I appreciate any example.
BASH has no helpful features for interpreting CGI data. CGI gives you a few predfined variables, a raw data stream, and that's it.

Use this script and see what appears when you throw a file into it:

Code:
#!/bin/sh

# disable filename globbing
set -f

echo "Content-type: text/plain; charset=iso-8859-1"
echo

echo CGI/1.0 test script report:
echo

echo argc is $#. argv is "$*".
echo

echo SERVER_SOFTWARE = $SERVER_SOFTWARE
echo SERVER_NAME = $SERVER_NAME
echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
echo SERVER_PROTOCOL = $SERVER_PROTOCOL
echo SERVER_PORT = $SERVER_PORT
echo SERVER_PROTOCOL = $SERVER_PROTOCOL
echo SERVER_PORT = $SERVER_PORT
echo REQUEST_METHOD = $REQUEST_METHOD
echo HTTP_ACCEPT = "$HTTP_ACCEPT"
echo PATH_INFO = "$PATH_INFO"
echo PATH_TRANSLATED = "$PATH_TRANSLATED"
echo SCRIPT_NAME = "$SCRIPT_NAME"
echo QUERY_STRING = "$QUERY_STRING"
echo REMOTE_HOST = $REMOTE_HOST
echo REMOTE_ADDR = $REMOTE_ADDR
echo REMOTE_USER = $REMOTE_USER
echo AUTH_TYPE = $AUTH_TYPE
echo CONTENT_TYPE = $CONTENT_TYPE
echo CONTENT_LENGTH = $CONTENT_LENGTH
echo "Content begins:"
echo =====
dd count=1 bs=$CONTENT_LENGTH
echo
echo =====
echo "Content ends"

From this and the CGI standard you can reverse-engineer what's going on and build your own solution if you really really want to.

PHP on the other hand has native support for CGI data.
# 7  
Old 03-01-2019
Thanks for the reply.

I will add little more information. I can read the web input from the bash script and I have no problem with form data like Name, Address, emal,...etc. When it comes to the file it seems I am only getting just the name.

Code:
DOCFILE="test.pdf"

Both these commands returned not true.
Code:
if [ -r "$DOCFILE" ] then ... fi
if [ -f "$DOCFILE" ] then ... fi

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-01-2019 at 03:36 PM.. Reason: Added CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Html form to submit data to bash script

hi all, im going to design a web html form so users can input what username and password they want to make the ftp account, once they enter in a username and password they click on the submit button and it submits it to a bash script and then the bash script will run and finish of making the... (3 Replies)
Discussion started by: robertkwild
3 Replies

2. UNIX for Dummies Questions & Answers

Read data from excel and upload into html page

Hi, I have requirement for automation, wanna confirm whether is it possible in shell scripting. 1) Need to read data from excel sheet 2) And upload the details in html page I know first requirement is possible by converting excel into csv form, but not sure about the second one. If... (6 Replies)
Discussion started by: stew
6 Replies

3. Shell Programming and Scripting

SSH Script For Automatic File Upload HELP

Hi guys! I hope this hasn't been asked too many times but, Would someone be able to help me write or point me in the direction to some helpful tutorials in order to write a script to transfer a file directly to a server via SSH from a linux based computer. The script should do as following:... (2 Replies)
Discussion started by: craigwilkinson
2 Replies

4. Shell Programming and Scripting

HTML code upload text file grep through shell script

I am looking for HTML code that browse text file and grep with database file then retrieve result txtfileuploaded contain 112233 115599 113366 shell code grep -F -f txtfileuploaded /data/database.txt result 112233 Mar 41$ 115599 Nov 44$ 113366 Oct 33$ attached... (2 Replies)
Discussion started by: phpshell
2 Replies

5. Shell Programming and Scripting

pass argument to html upload form

I am using an html form and a php upload script to upload files. HTML form <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table... (1 Reply)
Discussion started by: anil510
1 Replies

6. Shell Programming and Scripting

Get checkbox checked value from html page to the bash script

hi i m printing all current running processes into an html page with checkbox for each process , using bash script i want to get(retrive) the value of that checked checkbox to kill the process ,can anybody please helpme out thanks in advance (1 Reply)
Discussion started by: vagga06
1 Replies

7. Shell Programming and Scripting

Bash shell script that inserts a text data file into an HTML table

hi , i need to create a bash shell script that insert a text data file into an html made table, this table output has to mailed.I am new to shell scripting and have a very minimum idea of shell scripting. please help. (9 Replies)
Discussion started by: intern123
9 Replies

8. UNIX for Dummies Questions & Answers

Bash script to insert data into an html table

hi, I need to create a bash shell script which picks up data from a text file and in the output file puts it into an html made table. I have to use sed and awk utilties to do this the input text file will contain data in the format: job name para1 para2 para3 para4 para4 1 ... (1 Reply)
Discussion started by: intern123
1 Replies

9. Shell Programming and Scripting

bash script for ftp-upload is not working

Hello everyone, sorry for the title, most of you must getting sick of reading something like this, but I haven't found a solution, although I found many threads according to it. I'm working on a bash script that connects to a network printer with ftp where I want to upload a pdf created... (3 Replies)
Discussion started by: le_mae
3 Replies

10. Shell Programming and Scripting

help with a bash script to create a html table

Hi guys as the title says i need a little help i have partisally written a bash script to create a table in html so if i use ./test 3,3 i get the following output for the third arguement in the script i wish to include content that will be replace the A characters in the... (2 Replies)
Discussion started by: dunryc
2 Replies
Login or Register to Ask a Question