3

I am trying to move to intermediate level by learning the shell commands.

In online Linux forums it's often the consensus that to be an advanced Linux user one should know scripting. I myself have no experience with scripting the OS and don't know what the hype is about.

My understanding is that its just a convenient way for system admins to take backups by issuing a set of copy commands.

Is this understanding correct? What type of advanced tasks are commonly performed using scripting?

On the scale of 1 to 10, 1 being overrated hype and 10 being the magic potion for all your Linux woes, where does linux scripting stand?

1
  • 5
    Scripting lets you automate repetitive tasks of any sort, not just backups.
    – cjm
    Sep 1, 2012 at 7:58

4 Answers 4

13

Scripting is simply a form of programming. That's it, there's no magic.

These days, with a modern full-featured distribution of Linux, you can manage your system pretty much only using graphical interfaces. If what you need to do is covered by those tools, then you're fine, really.

Now if some of the tasks you need to do aren't covered by these interfaces, or you need to run them in the background, while you're asleep, on a computer you only have shell access to, ... then you'll need to use something else.

And the starting point for that "something else" on Unix-type systems is the shell and shell scripting.

Your Linux system comes with a very large toolbox of utilities for your shell. Stuff for file management (copy, move, find, compare files, etc.) and text file manipulation (printing, modifying, comparing, analysis, etc.) are very common since Unix-like systems are all about files, and most software (and OS) configuration files are plain text.
Start learning those if you have a need for them. Then look into tools for whatever it is you're interested in (media conversion, database stuff, website management, system monitoring, ... the list is endless).

Backups are one of the tasks that pretty much require automation. But anything repetitive can (and probably should) be automated.
Need to convert all your FLAC files to MP3 for your media player? Script it once, you'll be able to do that in one command next time.
Need thumbnails of your latest vacation shoot to put up on your website? Script it! (And script the website update too, while you're there.)
Need to clean out old log files? Script it, you'll need to do that again next week anyway.
Need to do pretty graphs for performance metrics on your server farm? Script the data gathering and graph generation, you'll have up-to-date data whenever you need it.
(In all cases above, use existing tools to do the grunt work, your scripts should glue them all together to make them work just like you want them to.)

Knowing scripting languages (not just the shell, and not just on Linux) is just like knowing other programming languages: the more you know, the more efficient you'll be since you'll have a large toolset to pick from when you need to get something done.

There's no "hype" factor: if you've got a task to do, pick the best tool to do it out of your toolbox. On Unix-type systems, if your toolbox doesn't have a shell and a couple of scripting languages, you're missing out on a lot of the fun.
But if you can do all you need to do with graphical interfaces, then you're fine, nothing wrong with that.

8

No, that understanding is not correct. Relating "scripting" to "usefulness on Linux" using a scale of 1-10 is meaningless.

Your miss-categorization of scripting as something that allows administrators to automate backups makes your question into "How useful is it to carry a spare tire in my car?"

Scripting in a Linux system is more closely equivalent to all the nuts, bolts, rods, brackets, clamps, and welds that hold your car together, all the wires, hoses gears and shafts that get things where they go and most of the machinery at the factory that put it together.

A Linux adminstrator without scripting skills is like a car mechanic without any wrenches. Maybe they can drive the car and punch buttons on the dash, but being able to program the radio doesn't make you a mechanic. For that you have to have tools.

6

This is a non-technical question, so I'm going to try to avoid any technical specifics and just write about what I think about scripting.

On your scale of 1 to 10: I'd say anywhere from 5-10 depending on what you're trying to do.

It can range from moderately useful to essential for avoiding spending hours or days doing what a computer can do in minutes. The main point of scripting is automation, especially of repetitive (boring) tasks or complicated tasks (prone to human error due to typing mistakes or distraction or forgetting one vital step).

(IMO, a secondary point of scripting is that it's practice in developing useful problem solving skills, to think about and analyse problems logically and methodically; to write a script, you need to break down what you're doing into discrete steps)

As a beginning Linux user, probably the thing you most need to learn about scripts is that scripting generally begins with annoyance at having to type the same sequence of commands repeatedly whenever you need to do the same thing. So you put those commands in a file, and you've now written your first script.

Later, you might modify it so that your script takes arguments from the command line (instead of having, e.g., hard-code file names). And later on you might want a script to do one of two (or more) different things depending on the circumstances, or you want a script to do the same thing repeatedly to multiple files, so you start looking into control structures like if;then;else, case statements, while and for loops, etc.

Learning to write scripts is an incremental process; you can start with small and simple things and gradually learn how to do more complicated things. Learning how to do simple things is as simple as learning how to type commands into a text editor and save them. It can take months or years to become 'good' at it, and a lifetime to truly master it. I've been writing sh and bash scripts using the usual Linux tools like awk and sed and grep for over 20 years and I'm still learning new things and new/improved ways of doing things or some obscure yet very useful option of tools I've been using for years.

I like the fact that there'll always be something new to learn. In fact, I think of that as kind of a tertiary reason for writing scripts - if I have something repetitive and tedious to do then writing a script to do it not only removes most of the scope for human error, it makes the job a hell of a lot more interesting to do. It might take me 2 or 3 hours to write a good script to do what I could have done manually in those same 2-3 hours, but I won't get anywhere near as bored or tired, and I'll get a lot more job satisfaction out of it. As a bonus, I also end up with a tool which might be useful in the future for automating similar jobs. Best of all, I might have learnt something new or interesting - or just honed my skill a little more - which I can make use of in the future.

0

Scripting is a fundamental portion of the Linux philosophy.

Let's take something that is at the opposite end of the spectrum: Windows. To be really brief, shell scripting is a good third of what differentiate Linux from Windows.

  • Linux is open-source. Windows is not.
  • Linux is free. Windows is not.
  • Linux has a shell structure that is conceived to let you pipe commands into other commands: a Linux command becomes a building block for something larger, usually a script. Windows has only windows.
4
  • You've never seen PowerShell. Sep 1, 2012 at 12:38
  • Yes, I've seen M$ PowerShell.
    – Avio
    Sep 1, 2012 at 12:46
  • 1
    Windows has lots of ways (including io streams similar to pipes) for programs to interact and build on each other. I'm not defending Windows (which I can't stand) but drawing this kind of comparison is really not useful. It confuses people who know Windows about how Linux differs because it doesn't make any sense relative to what they do know and it miss-informs people that don't know it.
    – Caleb
    Sep 1, 2012 at 13:04
  • Your last statement is not completely clear, however I continue to believe that such a comparison makes perfectly sense because that's how lot of people see Linux compared to Windows.
    – Avio
    Sep 1, 2012 at 13:12

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