Contents

What is Scripting and How is it different from programming?
- Every scripting language is a Programming Language, The one theoritical difference is programming languages are compile and then executed where as scripting languages donot have extra compilation step.
Live Example
- We have written two programs
- shell script
#!/bin/bash
tempfile="/tmp/available.$$"
trap "rm -f $tempfile" EXIT
cat << 'EOF' > $tempfile
{ sum += $4 }
END { mb = sum/1024
gb = mb/1024
printf "%.0f MB (%.2fGB) of availble diskspace\n", mb, gb
}
EOF
df -k | awk -f $tempfile
exit 0
#!/usr/bin/env python3
import shutil
path = "/"
total, used, free = shutil.disk_usage(path)
print("Total: %d GiB" % (total // (2**30)))
print("used: %d GiB" % (used // (2**30)))
print("free: %d GiB" % (free // (2**30)))
Approach – Part 1
- Any script is a set of instructions executed line by line
- To become effective understanding flow of the program/script is essentioal
Lets write a script to install docker
- create a file (
installdocker.sh
) with following content
#!/bin/bash
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
- Now give execute permissions and run the script
<path>/installdocker.sh
Exercises
- Write a shell script
- to install jenkins with java 11
- to install jenkins with java 17
- to install kubernetes (using kubeadm)
skip init
- Note: all the scripts will be run as a root user
Like this:
Like Loading...