TODO

1. Create a loading spinner

  • find out how to use arrays

  • learn to create scripts that run continuously

touch spinner && chmod u+x spinner && vim spinner
# !/usr/bin/env bash

# declare array
array=('-' '\' '|' '/')

# loop until stopped
while true; do
    # for every element in the array
    for c in "${array[@]}"; do

    # man echo
    # \-n     do not output the trailing newline
    # \-e     enable interpretation of backslash escapes
    echo \-en "\\r $c "

    # wait for half a second
    sleep .5

    # close for
    done
# close while
done

Run the script spinner

2. Creating a backup of your home

How to create a backup?

Creating an archive from a directory, adding also the date in the name.

tar --help
man tar
date

The script name will be BackUp1

Creating, adding permission and opening the file

touch BackUp1 && chmod u+x BackUp1 && vim BackUp1
# !/usr/bin/env bash

# create a backup of the home directory

tar -czf /tmp/home/backup`date +"%Y*%m_%d"` ~/sandbox

Task 1

Create a script wikiPython that reads a Wikipedia page - https://en.wikipedia.org/wiki/Python_(genus) (use curl command)

  1. extracts Species elements - python name (what kind of pythons are there) - use grep

  2. save the output the to a new file

  3. append to the new file the last line that is the count of species - using wc

Task 2

Create a script weather.py that give you the weather from curl https://wttr.in/(location)

  1. the location will be read from the keyboard - example weather Bucharest

  2. test that you have the location

  3. test that location is a valid string and doesn’t contain numbers using a regex operator compare a variable with $var =~ '^[0-9]+$'

Task 3

Create a health check script healthCheck that looks at:

  1. date and time

  2. the uptime of the machine

  3. how much disk df and memory usage free

  4. top most expensive process

  5. run this every 2 seconds using sleep or watch

Task 4

Create a script that reads the file source_code/scripting/data/ip.txt and:

  1. Find out how many different IPs?

  2. How many exit different codes?

  3. How many occurrences of each exit code?

  4. How often an IP appears?

  5. Which IP has experienced the most successes and failures?

Task 5

Create a script that reads the file source_code/scripting/data/hadoop.log and:

  1. Find out how many INFO, WARN ERROR messages are, and print the percentage compared to the total lines

  2. Which error appears most frequently?

  3. Are there any weird messages in the log?

Task 6

Create a script randomWords.sh that generated with 1000 random words file from the /usr/share/dict/words

  1. use shuf command to generate random words

  2. use head command to get the first 1000 words

  3. count all the words that have 9 characters using awk and wc

Task 7

Create a Makefile that has the following targets:

  1. install - that installs the script healthCheck in /usr/local/bin

  2. uninstall - that removes the script healthCheck from /usr/local/bin

  3. test - that runs the script healthCheck and saves the output to a file healthCheck.log