Add bash scripts
This commit is contained in:
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Git demo
|
||||||
|
|
||||||
|
|
||||||
|
This project contains 5 bash scripts, and 3 branches we can use for testing.
|
||||||
31
scripts/backup.sh
Normal file
31
scripts/backup.sh
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
ARCHIVE="/home/ubuntu/backup.tar.gz"
|
||||||
|
LOG_DIRECTORY="/home/ubuntu/logs"
|
||||||
|
|
||||||
|
if ! [[ -d "$LOG_DIRECTORY" ]]; then
|
||||||
|
echo "Log directory not found: $LOG_DIRECTORY"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
log_count=0
|
||||||
|
|
||||||
|
for file in "$LOG_DIRECTORY"/*.log; do
|
||||||
|
if [[ -f "$file" ]]; then
|
||||||
|
log_count=$(( log_count + 1 ))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
echo "Found $log_count log files."
|
||||||
|
|
||||||
|
|
||||||
|
if (( log_count > 0 )); then
|
||||||
|
tar czf "$ARCHIVE" "$LOG_DIRECTORY"/*.log
|
||||||
|
echo "Successfully created archive: $ARCHIVE"
|
||||||
|
else
|
||||||
|
echo "No files found, skipping backup."
|
||||||
|
fi
|
||||||
14
scripts/countdown.sh
Normal file
14
scripts/countdown.sh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
counter=${1:-10}
|
||||||
|
|
||||||
|
|
||||||
|
while (( counter > 0 )); do
|
||||||
|
echo "$counter"
|
||||||
|
sleep 1
|
||||||
|
(( counter-- ))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Tada..."
|
||||||
18
scripts/fruits.sh
Normal file
18
scripts/fruits.sh
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
liked_count=0
|
||||||
|
total_count=0
|
||||||
|
|
||||||
|
|
||||||
|
for fruit in banana apple strawberry; do
|
||||||
|
read -p "Do you like $fruit (y/n): " answer
|
||||||
|
if [[ "$answer" == y* ]]; then
|
||||||
|
liked_count=$(( liked_count + 1 ))
|
||||||
|
fi
|
||||||
|
|
||||||
|
total_count=$(( total_count + 1 ))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Liked $liked_count fruits out of $total_count"
|
||||||
7
scripts/hello.sh
Normal file
7
scripts/hello.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
read -p "Your name: " name
|
||||||
|
today=$(date "+%d-%m-%Y")
|
||||||
|
echo "Hello $name. Today is $today."
|
||||||
14
scripts/path.sh
Normal file
14
scripts/path.sh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
read -rp "Path: " input_path
|
||||||
|
|
||||||
|
|
||||||
|
if [[ -f "$input_path" ]]; then
|
||||||
|
echo "It's a file."
|
||||||
|
elif [[ -d "$input_path" ]]; then
|
||||||
|
echo "It's a directory."
|
||||||
|
else
|
||||||
|
echo "It's neither."
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user