Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

How to do it...

This Bash script combines different commands, to track changes in a web page:

#!/bin/bash 
#Filename: change_track.sh 
#Desc: Script to track changes to webpage 

if [ $# -ne 1 ]; 
then  
  echo -e "$Usage: $0 URL\n" 
  exit 1; 
fi 

first_time=0 
# Not first time 

if [ ! -e "last.html" ]; 
then 
  first_time=1 
  # Set it is first time run 
fi 

curl --silent $1 -o recent.html 

if [ $first_time -ne 1 ]; 
then 
  changes=$(diff -u last.html recent.html) 
  if [ -n "$changes" ]; 
  then 
    echo -e "Changes:\n" 
    echo "$changes" 
  else 
    echo -e "\nWebsite has no changes" 
  fi 
else 
  echo "[First run] Archiving.." 

fi 


cp recent.html last.html 

Let's look at the output of the track_changes.sh script on a website you control. First we'll see the output when a web page is unchanged, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985