Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

7 Answers 7

up vote 13 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
+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 '10 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. –  Bruce Ediger Oct 5 '10 at 22:02

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.

share|improve this answer
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 '10 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. –  Denilson Sá Aug 17 '10 at 23:52

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.

share|improve this answer

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

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.