I've recently written a comprehensive bash script with functions for handling various PostgreSQL database operations, including creating and dropping databases and users. I'm eager to hear your feedback on it! Here's a quick overview of the two main scripts I created: `logger_utils.sh` for logging messages, and `postgres_utils.sh` for database operations. It's my first time working on something this extensive, so any advice on improvements or critiques would be greatly appreciated. What do you think?
5 Answers
Just a small tip, when you reference your logger script, the line `# shellcheck source=/dev/null` might not be necessary—it’s more of an informational tag and could confuse some users. If it’s not needed, you can simplify that line.
Just a thought: your scripts seem designed for a desktop environment, but consider that PostgreSQL is often run on servers without a `Desktop` directory. You might want to structure the paths accordingly for a more server-friendly approach.
I noticed you're using `date +"%Y-%m-%dT%H:%M:%S%z"` for timestamps. You can simplify that with `printf -v timestamp '%(%FT%T%z)T' -1` so it’s a bit cleaner.
Also, make sure you implement proper error handling in your main functions. Using shell options like `set -e` and defining traps can help catch errors effectively.
Great job on the script! Just a heads up, for color support, you might want to avoid hardcoding colors like `COLOR_RED='33[0;31m'`. Instead, use `tput` for terminal capabilities to make it more robust across different environments.

Or just use `date -Is` for an even simpler approach!