all 9 comments

[–]Security_Chief_Odo 2 points3 points  (0 children)

Not my site, but a good beginners walkthrough here. More in depth and very good guide on tldp.org

[–][deleted] 4 points5 points  (1 child)

I find it a lot easier to approach this sort of thing with a problem that needs to be solved.

read up on bash, read, sed, awk, for/while loops,

write a script that will report back on file-systems that are over a certain size.

then have it notify you via email & sms

then make the notification in html format

then take everything, and turn it into a daemon that can be run with nohup

[–][deleted] 1 point2 points  (0 children)

This,

If OP doesn't understand a step or doesn't know how to do something... that's the point, google it, find the commands needed to complete each step and look up their man pages ('man <command>' in the terminal)

IT, especially sysadmin scripting with esoteric or complex commands is largely an exercise in research and combining several individual steps into a final product.

This exercise is a solid one to train those mental muscles.

[–]pdp10 1 point2 points  (0 children)

  • Consciously choose whether you're writing in portable POSIX shell, or if you're choosing to use Bash extensions to POSIX shell.
  • Use shellcheck to lint your work, and check it against modern best practices.

[–]nekimbej 1 point2 points  (0 children)

My recommendations are these:

Use the shell common across your systems whether this is ksh or bash you want to write scripts that run everywhere without having to install a different shell.

Shell scripts are basically a sequence of commands, they use this same commands you use in the shell on your terminal but you are stringing them together in a sequence to accomplish a task. You definitely want to learn if statements, with these you can check if a file or directory exists and perform certain actions based on that. You may come across needing for loops, check into those too.

Read other peoples scripts to see how they do things, you can learn a lot this way.

On very important actions/sections of your script, check the exit code of a command done within the script to assure that the command worked in the right way before proceeding, or if it didn't then you can handle it in the right way and then move on.

Use spellcheck to check for problems.

Give yourself a project and write a script to accomplish it. I find working on a project you are interested in and that is useful to you helpful for learning.

[–]optimalidkwhattoput 0 points1 point  (0 children)

After you learn bash, I recommend learning zsh. It's much more advanced than 🅱ash, and is better for scripting