Files
dotfiles/scripts/shell/gallery-dl-queuer.sh
2023-11-06 03:16:17 -03:00

48 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Initialize variables for output files
success_log="success_log.txt"
failure_log="failure_log.txt"
# Parse command line arguments
while getopts "f:c:" opt; do
case $opt in
f)
queue_file="$OPTARG"
;;
c)
command="$OPTARG"
;;
\?)
echo "Usage: $0 -f <queue_file> -c <command>"
exit 1
;;
esac
done
# Check if both parameters are provided
if [ -z "$queue_file" ] || [ -z "$command" ]; then
echo "Usage: $0 -f <queue_file> -c <command>"
exit 1
fi
# Check if the queue file exists
if [ ! -f "$queue_file" ]; then
echo "Queue file not found: $queue_file"
exit 1
fi
# Process the queue
while IFS= read -r line; do
# Execute the command with the line as an argument
$command "$line"
# Check the exit status of the command
if [ $? -eq 0 ]; then
echo "Command: $command $line - SUCCESS" >> "$success_log"
else
echo "Command: $command $line - FAILURE" >> "$failure_log"
fi
done < "$queue_file"
echo "Script completed. Successful commands logged in $success_log. Failed commands logged in $failure_log."