12

I'm looking for some common problems in unix system administration and ways that shell scripting can solve them. Completely for self-educational purposes. Also I'd like to know how would you go about learning shell scripting.

7 Answers 7

14

Any time you EVER find yourself doing something multiple times, script it. Think as lazy as you possibly can. Computers were built to do all of that menial crap. Any thing that smells like busy work needs a shell script.

Personally, I learned by rummaging around in Slackware for a couple of years. See what happens when you strip your system back as much as possible. Learn to be comfortable with text. While everybody else is ooing and awing over NetworkManager, learn how simple it is to make your own damn NetworkManager. Sure, it might not have as many use cases, but you can get something up and running, dynamically connecting via ethernet and wireless on-demand pretty simply enough.

6

I would like to re-recommend the three books that I suggested in another thread, these are in my opinion the best books to get into the spirit of Unix:

  • The Unix Programming Environment from Kernighan and Pike
  • Unix for the Impatient
  • O'Reilly's Unix Power Tools.

The first one is old, very old, but it is concise, a short read and will give you the shell chops that you need (regular expressions, sed, pipelines).

The second one is incredibly entertaining.

The third one is a collection of "best of" tricks from the Unix masters in the 90's (That is when I read it). The book keeps getting re-edited, so I am sure it contains many new nuggets.

2
  • +1 for The Unix Programming Environment. After reading this, suddenly Unix made an awful lot more sense to me. A bit of a revelation :-)
    – dr-jan
    Aug 19, 2010 at 17:52
  • The Unix Programming Environment is one of the few books that covers "here documents" at all. You can do a lot with "here documents" that many think is impossible to do in a single file.
    – user732
    Oct 5, 2010 at 22:02
5

There is a wealth of great information in the Advanced Bash-Scripting Guide, and it's frequently updated to stay current.

2

How to learn it: Fall in love with the command-line. Use it regularly and pull up man pages often. Frequently, even. When I was first learning scripting, I couldn't count how many times I typed man bash. I also couldn't count how many times I pulled up the man page for another command.

2
  • 1
    +1 to Kevin. I learnt scripting the same way. The scenario typically being that I would need to process these COBOL data files (yeah, that far back ... but this is COBOL on UNIX, not on Mainframes!!). Instead of cranking COBOL code, I would fire up awk (not even perl since it was not installed on our server), and do things like top 50 customers report :-)
    – user352
    Aug 15, 2010 at 14:05
  • I use xterm (or any terminal, if that matters) as my main file manager. Thus, I kinda forced myself into using shell ALL the time, which made me learn and develop some tricks over time. Aug 17, 2010 at 23:52
2

I learned it by writing a monitoring tool. It would connect to a bunch of machines via ssh and collect data like uptime, load, number of active connections, memory utilization and stuff like that. On my local machine it would show me that data as a text table.

1

I second Miguel's recommendation of 'The Unix Programming Environment'. Its really old but its how I learned almost everything I know about the shell and because its so old you can get it for just a few bucks on amazon: http://is.gd/eiSn6

0

Find a book or a manual and treat your chosen shell like a programming language, because it is. (Well, maybe not csh...)

For starters, learn how to figure out if you're in a Bash shell, Bourne shell, csh, zsh, or whatever. Some of these are similar to eachother like C and C++ -- deceptively different -- so knowing which one you're fighting with will help you find examples and manuals that actually will help in a given situation.

Not the answer you're looking for? Browse other questions tagged .