From 6a897b18da61d105106d948643d84d29955b2b48 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Mon, 16 Sep 2024 15:44:53 -0600 Subject: [PATCH] check_file_exists --- check_file_exists | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 check_file_exists diff --git a/check_file_exists b/check_file_exists new file mode 100644 index 0000000..e0dd91d --- /dev/null +++ b/check_file_exists @@ -0,0 +1,24 @@ +#!/bin/bash + +# Parse command line arguments +while [[ "$#" -gt 0 ]]; do + case $1 in + --file) file="$2"; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + +if [[ -z "$file" ]]; then + echo "No file provided. Please provide a file with --file." + exit 3 +fi + +# Check if file exists +if [[ -f "$file" ]]; then + echo "OK - \"$file\" exists." + exit 0 +else + echo "CRITICAL - \"$file\" does not exist." + exit 2 +fi