36 lines
749 B
Bash
Executable File
36 lines
749 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Usage: is_keyspace_exists.sh [--keyspace <keyspace>]
|
|
# Example: is_keyspace_exists.sh --keyspace dev_keyspace_1
|
|
|
|
KEYSPACE=${KEYSPACE:-}
|
|
|
|
# Parse arguments
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--keyspace)
|
|
KEYSPACE="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
echo "Unknown argument: $1"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Check for required arguments or environment variables
|
|
if [ -z "$KEYSPACE" ]; then
|
|
echo "KEYSPACE is not set. Set it via --keyspace or KEYSPACE environment variable."
|
|
exit 1
|
|
fi
|
|
|
|
IP_ADDRESS=$(hostname -I | awk '{print $1}')
|
|
|
|
if cqlsh $IP_ADDRESS -e "DESCRIBE KEYSPACE $KEYSPACE;" > /dev/null 2>&1; then
|
|
echo "Keyspace $KEYSPACE EXISTS"
|
|
exit 0
|
|
fi
|
|
echo "Keyspace $KEYSPACE DOES NOT EXIST"
|
|
exit 1
|