Bash

Facebook Twitter

System Administrator Cheat Sheet. Questions 1.

System Administrator Cheat Sheet

What are the different ways to check the load average on a system? Vmstat, top, uptime, w, procinfo ================================ ================================ Bonus - Describe the 3 values that top/uptime shows 1-minute, 5-minute and 15-minute load averages ================================ ================================ 2. What are the different running states of a SOLARIS system? 3. 4. 5. 6. 7. For log files older than 5 days find /opt/app/logs/ -name *.log -mtime +5 -exec ls -tl {} \; find /opt/app/logs/ -name *.log -mtime +5 -exec rm -f {} \; For log files newer than 5 days. 2009.03.04 - Parallelizing Jobs with xargs. With multi-core processors sitting idle most of the time and workloads always increasing, it's important to have easy ways to make the CPUs earn their money's worth.

2009.03.04 - Parallelizing Jobs with xargs

My colleague Georgios Gousios told me today how the Unix xargs command can help in this regard. The GNU xargs command that comes with Linux and the one distributed with FreeBSD support a -P option through which one can specify the number of jobs to run in parallel. Using this flag (perhaps in conjunction with -n to limit the number of arguments passed to the executing program), makes it easy to fire commands in parallel in a controlled fashion.

Georgios sent me an example, where he sped up a job by almost seven times through this technique. $ ls -l *.eps|wc 192 1537 17651 $ time find . The xargs -P flag can also be useful for parellelizing commands that depend on a large number of high-latency systems. Read and post comments. BashPitfalls - Greg's Wiki. This page shows common errors that Bash programmers make. The following examples are all flawed in some way: 1. for i in $(ls *.mp3) One of the most common mistakes BASH programmers make is to write a loop like this: for i in $(ls *.mp3); do # Wrong! Some command $i # Wrong! Never use a CommandSubstitution -- of EITHER kind! Why? Possibly worse, the strings that resulted from the previous word splitting step will then undergo pathname expansion. You can't double-quote the substitution either: for i in "$(ls *.mp3)"; do # Wrong!

This causes the entire output of ls to be treated as a single word. In addition to this, the use of ls is just plain unnecessary. For i in *.mp3; do # Better! POSIX shells such as Bash have the globbing feature specifically for this purpose -- to allow the shell to expand patterns into a list of matching filenames. Question: What happens if there are no *.mp3-files in the current directory? # POSIX for i in *.mp3; do [ -e "$i" ] || continue some command "$i" done 3.