Automating Web Tasks Using Curl and Bash Scripts

In my previous blog article, I explained how to use Firefox plugin to automate the tedious web tasks. In this article I will explain how to use Linux command curl and bash scripts to automate the web tasks and it is faster than using the plugin and the code can be modified to suit other web automation tasks as well.


Our task is to update about 300 network security tickets generated by the network scanner Nessus in the web form and submit them using curl instead of manually click the submit button. It would take an hour to do the job by hand and now by using curl, it only takes less than 30 seconds.

The Network Scanning Ticket Portal

First the complete code is here

# curl parameter explained:
# -s, silent mode
# -D, write the response http header to file or stdout by using "-D -"
# --data, http POST data contents
# -c, save the cookies to file path
# -b, use the cookes from file path
# -o, output response to file path
# Credentials for the NUS SVMS website login

# This string will be used to locate the content/lines we want to extract from the html response
search_string="Search Ticket Result"

# Get cookies from website by send POST API request to the login web page
curl -s -D - -X POST --data "userid=$username&passwd=$password&submit=Login" -c /tmp/cookies.txt \ -o /dev/null

# Use obtained cookies to access the ticket information API web page by GET method 
# Save the response html content to a local file for parsing data
curl -s -D - -X GET --data 'status=unresolved' -b /tmp/cookies.txt \ -o /tmp/output

# The start Line number of the html response file, can ignore the previous lines
start_line=$(grep -n "$search_string" /tmp/output | cut -d ":" -f 1)

# Parse the ticket number count from the html response file
ticket_no=$(grep -n "$search_string" /tmp/output | cut -d ":" -f 2 | cut -d "-" -f 2 | cut -d " " -f 2)

# First skipped lines from start line to the ticket id location line

# Subsequent skipped lines from ticket id to ticket id

# First ticket id line number
#echo $line

# Loop through all the html content and based on each line number of the ticket id
# Send the API POST request to update the ticket information
# If the update is successful, display "successful" information on the console
for (( i=0;i<$ticket_no;i++))
    ticket_id=$(awk -v var="$line" 'NR==var {print $0}' /tmp/output | cut -d ">" -f 2 | cut -d "<" -f 1)
    curl -s -D - -X POST --data "scanticket_pkey=$ticket_id&status=justified&remarks=No+Impact&submit=Update" \
        -b /tmp/cookies.txt --referer$ticket_id \ | if grep -q "has been updated successfully"; \
        then echo "updated Ticket ID: ${ticket_id} successfully"; fi

To run the code in Ubuntu Linux:

sudo chmod a+x


  1. Login to get cookies from the server
  2. Request the server to get ticket ids by using obtained cookies
  3. Obtain the start line number of the HTML response so we can parse the ticket id. Also count how many ticket id we have to deal with.
  4. Send update requests to the server repeatedly until the last ticket id is updated.


The curl, cut and grep commands are easy to understand by issuing “man curl” and “man grep” to read the help documentations.

The awk command used built-in variablesNR” (Number of Records Variable) and map it with html response line number.

ticket_id=$(awk -v var="$line" 'NR==var {print $0}' /tmp/output | cut -d ":" -f 2 | cut -d " " -f 1)

It also used “-v” parameter to pass the shell/bash script variable “$line” into awk as a new variable “var“.


If you want to use this script on other websites for automation purpose, you may need to modify the request URI and text match/find patterns in the code to make it working.

Happy coding!

Automating Web Tasks Using Curl and Bash Scripts

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s