Looking for Feedback on My PostgreSQL Utility Scripts

0
1
Asked By CraftyCoder92 On

Hey everyone! I've written a couple of bash scripts for PostgreSQL operations and I'm looking for some feedback. One script, `logger_utils.sh`, contains functions for logging various types of messages with color support while the other, `postgres_utils.sh`, handles common database operations like creating, dropping databases and users, and dumping/restoring databases. This is the first time I've put together something this comprehensive, so I'm eager to hear any critiques or suggestions for improvement. Thanks for your help!

4 Answers

Answered By CuriousScripter On

Just a heads-up, your scripts might have issues when run on a non-interactive server environment where there’s no ${HOME}/Desktop. It's better to allow scripts to adapt to the server setup. Also remember to implement better error handling to avoid crashes! Utilizing log levels could help keep things tidy in your logs.

Answered By SkepticalDev21 On

About your color handling: If you're scripting for Unix-like systems, there's a better way to check for terminal colors. Directly setting color codes might mess up user preferences or terminal types. It's safer to use `tput` for color support. This way, you can ensure compatibility across different terminal emulators. Check out [this guide](https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x241.html) for more tips!

Answered By QuickFixer On

Make sure to format your code snippets properly for clarity. It makes a big difference when you're sharing scripts. A simple method is to use four spaces before each line of code and leave a blank line between code and text for better readability!

Answered By DevGuru88 On

I like your setup! But when you get the current timestamp, consider simplifying it using `printf` instead of calling `date`. You can get the same format with `printf -v timestamp '%(%FT%T%z)T' -1`, which is a bit cleaner.

CraftyCoder92 -

Oh, good point! I hadn't thought of that! Thanks for the tip!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.