Skip to content

Instantly share code, notes, and snippets.

@DanielChuDC
Created April 7, 2024 13:57
Show Gist options
  • Save DanielChuDC/12541307d76ea944dc04d81939fe5bd5 to your computer and use it in GitHub Desktop.
Save DanielChuDC/12541307d76ea944dc04d81939fe5bd5 to your computer and use it in GitHub Desktop.
#!/bin/bash
target_dirs="/opt/"
target_tools=(
"scp"
"ssh"
)
function print_report() {
local input="$1"
local indent="$2"
local depth="$3"
if [ -d "$input" ]; then
echo "${indent}Contents of directory: $input"
while IFS= read -r -d '' item; do
local item_name="${item##*/}" # Extract the name of the file or directory
if [ -d "$item" ]; then
echo "${indent}├─ Directory: $item_name"
print_report "$item" "│ $indent" "$((depth + 1))"
elif [ -f "$item" ]; then
echo "${indent}├─ File: $item_name"
echo "${indent}│"
echo "${indent}└─ Content:"
local line_number=1
while IFS= read -r line; do
printf "%s%s: %s\n" "$indent" "$line_number" "$line"
((line_number++))
done < "$item"
fi
done < <(find "$input" -mindepth 1 -maxdepth 1 -print0)
elif [ -f "$input" ]; then
echo "${indent}├─ File: $input"
echo "${indent}│"
echo "${indent}└─ Content:"
local line_number=1
while IFS= read -r line; do
printf "%s%s: %s\n" "$indent" "$line_number" "$line"
((line_number++))
done < "$input"
else
echo "Error: Input is neither a file nor a directory"
fi
}
echo "Checking for system tools in target directories..."
echo ""
for tool in "${target_tools[@]}"; do
echo "Searching for tool: $tool"
echo ""
for directory in $target_dirs; do
echo "Directory: $directory"
echo ""
print_report "$directory" "" 0
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment