#!/bin/bash
source /home/$LOGNAME/.env
# Ensure at least two arguments are provided
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <command> <file_path> [additional_args...]"
exit 1
fi
# Extract filename from the second argument
filename=$(basename "$2")
# Define log directory and log file path
log_dir="/stage/$LOGNAME/logs/$filename"
log_file="$log_dir/$(date +%d).log"
# Create log directory if it doesn't exist
mkdir -p "$log_dir"
# Redirect STDOUT and STDERR to the log file (no output on terminal)
exec >> "$log_file" 2>&1
echo "Executing "$@" at `date`"
# Execute the provided command
eval "$@"
No comments:
Post a Comment