Filling out Web Form from Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filling out Web Form from Script
# 1  
Old 12-12-2009
Filling out Web Form from Script

I am trying to fill out a web form from within a script I am writing. I think that I should be using curl to do this, but I'm not really sure. The form has username and password fields and a submit button. I want to be able to log in from the command line.

Html from the site:
Code:
<h5 align="center"><font color="#000000"><div align="center">
    <table class = "singleTable" width="400" height="275" id="table1">
        <tr>
            <td>
                <form action="https://safeconnect.bucknell.edu:8443/authenticate.!^" name="loginForm" method="post" onsubmit="return validateForm(this)" >
                      <table width="100%" id="table2">
                        <tr>
                            <td colspan="2">&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <p align="right"><label for="username">Network Username:</label></td>
                            <td> 
                              <input type="text" name="userId" id="    " tabindex="1" accesskey="u" value="" size="16" /></td>
                        </tr>
                        <tr>
                            <td>
                                <p align="right">Password:</td>
                            <td>
                              <input type="password" name="pass" id="password" tabindex="2" accesskey="p" value="" size="16" /></td>
                        </tr>
                        <tr>
                            
                        </tr>
                        <tr>
                            <td colspan="2">
                            <p align="center">
                            <div style="display: none;" id="autherror">
                                    <h5 align="center"><font color="#000000">Please enter valid credentials</font></h5>
                                </div>
                            <p align="center">
                            <input type="submit" tabindex="3" accesskey="l" value="Submit" /></td>
                        </tr>
                        
                    </table>
                    
                </form>
            </td>
        </tr>
    </table>
</div></font></h5>
</div>

Any help would be greatly appreciated.
# 2  
Old 12-12-2009
You can get a script from the curl website called formfind. You download the html page or just save your post to an html file, then run formfind on it (./formfind < index.html). You will get some output like:

Code:
 --- FORM report. Uses POST to URL "https://safeconnect.bucknell.edu:8443/authenticate.!^"
Input: NAME="userId" (TEXT)
Input: NAME="pass" (PASSWORD)
Button: "Submit" (SUBMIT)
--- end of FORM

That tells you the things you need to input, what they're called, and what url the data actually gets sent to.

You then use curl with those values:
curl -d "userId=YOURNAME&pass=YOURPASS" 'https://safeconnect.bucknell.edu:8443/authenticate.!^'

or

curl -d userId=YOURNAME -d pass=YOURPASS" 'https://safeconnect.bucknell.edu:8443/authenticate.!^'

I only single quoted the url because of the "!^" at the end. Quotes aren't normally needed. Sometimes you may need to use "curl -k" and sometimes the -d needs to be -F. I haven't read up on it, but I have 3 systems, and all three need a different curl command for the same site.
# 3  
Old 12-14-2009
Thanks. That was just what I was looking for. It works perfectly.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] script is filling up my /var/log

I am trying to create a script that checks if my VPN connection is up and running... Everything seems to work as except but for some reason, the script fills up my /var/log/auth.log with the below information Dec 13 01:07:44 debian sudo: soichiro : TTY=pts/0 ; PWD=/home/soichiro/Desktop ;... (5 Replies)
Discussion started by: soichiro
5 Replies

2. Shell Programming and Scripting

Trying to submit web form content to a shell script

Hi I was hoping some one could help me with a problem I have. I am trying to collect some information from a web form and save it to a text file. I found an example on this site that is sort of what I am trying to accomplish, the shell script bellow should echo the input back to the browser... (0 Replies)
Discussion started by: Paul Walker
0 Replies

3. UNIX for Beginners Questions & Answers

How to use cURL to download web page with authentification (form)?

Hello, I'm new in the forum and really beginer, and also sorry form my bad english. I use linux and want to create little program to download automaticaly some pdf (invoices) and put in a folder of my computer. I learn how to do and programme with ubuntu but the program will be implemented... (1 Reply)
Discussion started by: MarcelOrMittal
1 Replies

4. Shell Programming and Scripting

Multiple variables using awk and for loop for web form submission

Hi My goal is to fill an HTML form and submit. What I have managed to do: 1. curl command to fill up the form and submit 2. a file which has the input curl command: curl -v -b cookie.txt -d __CSRFToken__=dc23d5da47953b3b390ec68d972af10380908b14 -d do=create -d a=open -d... (10 Replies)
Discussion started by: zorrox
10 Replies

5. Shell Programming and Scripting

Script filling password from command line

I have this command that i am calling from php (exec()): openssl pkcs12 -export -in cert.pem -inkey key.pem -out cred.p12 and then i need to insert password twice Enter Export Password: Verifying - Enter Export Password: I need script that will fill the password... (3 Replies)
Discussion started by: rockyada
3 Replies

6. Shell Programming and Scripting

Pass values from web form to shell script

Hi, is it possible to pass more values from web form like textbox to shell script and if yes,how to do that.:confused::confused::confused: (2 Replies)
Discussion started by: tdev457
2 Replies

7. Programming

Creating a web based id request form

Please pardon my ignorance, but I need to create a web-based form which can be used to request access to the unix servers in our environment. It just needs to have input fields for basic info (name, dept., etc.), and perhaps a drop-down box with the names of the servers. The form will be submitted... (2 Replies)
Discussion started by: wjssj
2 Replies

8. Shell Programming and Scripting

Transfer files with web based form by date

Not sure how I should approach this one. I have server X and Server Y. X is a collector. All files are seperated by hour. Y is used strictly for analysis. I do not always need all files from X. Sometimes other people use Y for analysis and do not always know how to transfer the files from... (3 Replies)
Discussion started by: mrlayance
3 Replies

9. Shell Programming and Scripting

simple script to alert of archive logs filling

Hi all. I am not a DBA. But I do have responsibility for making sure the archive logs dont fill up and cause the database. This happend the other day while I was absent (sick) and I got a good ticking off for it. Needless to say I dont want this happen! Could anyone lend a hand to a... (8 Replies)
Discussion started by: Incremental
8 Replies
Login or Register to Ask a Question