Putting It Together - Some Useful Examples
In this lesson, you’re going to see many of the ideas you’ve learned put together in more realistic contexts, so you can get a flavour for what bash can do for you on a day-to-day basis.
We'll cover the following...
How Important is this Lesson?
You can easily skip this lesson if you want as nothing here is new, but following this can embed some concepts and keep your motivation going before the final part!
Output With Time
Frequently, I want to get the output of a command along with the time. Let’s say I’m running vmstat while a server is having problems, and I want to ensure that I’ve logged the time that vmstat relates to. Type this in:
function dateit() {while read linedoecho "$line $(date '+ %m-%d-%Y %H:%M:%S')"done}vmstat 1 | dateit
Note:
vmstat
is a program available on most Linux flavours that gives you a view of what the system resource usage looks like. It is not available on Mac OSes. If vmstat does not exist for you, then replace withvm_stat
, which should be available.
You should be able to follow what’s happening there based on what you’ve learned so far in