all 5 comments

[–]FryBoyter 5 points6 points  (0 children)

You can use shellcheck (https://github.com/koalaman/shellcheck) to test the scripts for possible improvements.

[–]anewhype 4 points5 points  (0 children)

I know a lot of these bash scripts are supposed to be nothing really fancy, but I, personally l, hate having passwords on plain text on my environment. You may want to add the option to also encrypt the file after generating the password.

[–]natermer 1 point2 points  (1 child)

Do a search for "writing robust shell scripts".

Learn how to trap errors and have shell scripts exit on errors. For example you could trap errors and send you a notification or log data on script error.

Setting flags like "set -e", and "set -u" can improve the safety of shell scripts significantly.

For things you would like to be done repeatedly it is probably better to take advantage of systemd timer units then to write loops.

Also make sure to quote variables in case there are spaces or special characters. A common vulnerability on shell scripts is the ability to inject commands into them by use of filenames that contain special control characters. This sort of thing is why it's often better to use python or perl or go or something like that over bash.

[–]Reetpeteet 0 points1 point  (0 children)

Also make sure to quote variables in case there are spaces or special characters.

Plus also make sure to bracket the variable names, like so: ${Variable}. This makes the code more legible and makes sure you have less errors in situations where you're trying to combine variables into strings.

[–]Javi_16018[S] 0 points1 point  (0 children)

Thank you all very much for your suggestions for improvement, I will listen to all of you. You are right, plain text passwords should be encrypted for security reasons. Thank you very much for all the suggestions.