Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Linux Shell Scripting Bootcamp

You're reading from   Linux Shell Scripting Bootcamp The fastest way to learn Linux shell scripting

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher Packt
ISBN-13 9781787281103
Length 208 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
James K Lewis James K Lewis
Author Profile Icon James K Lewis
James K Lewis
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Linux Shell Scripting Bootcamp
Credits
About the Author
Acknowledgement
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Getting Started with Shell Scripting FREE CHAPTER 2. Working with Variables 3. Using Loops and the sleep Command 4. Creating and Calling Subroutines 5. Creating Interactive Scripts 6. Automating Tasks with Scripts 7. Working with Files 8. Working with wget and curl 9. Debugging Scripts 10. Scripting Best Practices Index

Making a current backup of your work


And now, for another bonus the next section shows the script I used to backup my current book's chapter every 60 seconds:

Chapter 4 – Script 7

#!/bin/sh
#
# Auto backs up the file given if it has changed
# Assumes the cbS command exists
# Checks that ../back exists
# Copies to specific USB directory
# Checks if filename.bak exists on startup, copy if it doesn't

echo "autobackup by Lewis 5/9/2017 A"
if [ $# -ne 3 ] ; then
 echo "Usage: autobackup filename USB-backup-dir delay"
 exit 255
fi

# Create back directory if it does not exist
if [ ! -d back ] ; then
 mkdir back
fi

FN=$1                        # filename to monitor
USBdir=$2                    # USB directory to copy to
DELAY=$3                     # how often to check

if [ ! -f $FN ] ; then       # if no filename abort
 echo "File: $FN does not exist."
 exit 5
fi

if [ ! -f $FN.bak ] ; then
 cp $FN $FN.bak
fi

filechanged=0
while [ 1 ]
do
 cmp $FN $FN.bak
 rc=$?
 if [ $rc -ne 0 ] ; then
  cp...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Banner background image