33 lines
786 B
Bash
33 lines
786 B
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
# Usage: ./run_batch_job.sh docker_image command [additional_args...]
|
||
|
|
|
||
|
|
# Check for at least two arguments
|
||
|
|
if [ "$#" -lt 2 ]; then
|
||
|
|
echo "Usage: $0 docker_image command [additional_args...]"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
DOCKER_IMAGE=$1 # The Docker image to use
|
||
|
|
COMMAND=$2 # The command to run inside the container
|
||
|
|
shift 2 # Shift the arguments to access additional arguments
|
||
|
|
|
||
|
|
# Pass remaining arguments to the Docker container
|
||
|
|
echo "Running Docker container with image: $DOCKER_IMAGE"
|
||
|
|
echo "Command: $COMMAND"
|
||
|
|
echo "Arguments: $@"
|
||
|
|
|
||
|
|
OUTPUT=$(docker run --rm "$DOCKER_IMAGE" "$COMMAND" "$@")
|
||
|
|
|
||
|
|
# Check the result
|
||
|
|
if [ $? -ne 0 ]; then
|
||
|
|
echo "Error running Docker container."
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "Command output:"
|
||
|
|
echo "$OUTPUT"
|
||
|
|
|
||
|
|
echo "Job completed successfully."
|
||
|
|
|