Unix-like

How to copy a file and print the progress

There can be a number of reasons for starting a file copy from the command line (eg. you're on a headless server Smiling ). Copying large files (eg. virtual machine images) can take some time and without feedback you can just guess how much is still left. The dd command can print the desired progress, but it takes more than just a command line option to get there. Here's an example to make it print the progress every 10 seconds:
dd if=input_file of=output_file bs=1M & pid=$! && while sleep 10 && kill -USR1 $pid 2> /dev/null; do :; done

Optimizing NFS Performance

If you see performance problems with your NFS fileserver, you should most probably look into the following pages:
I found the most helpful the chapters "5.6. Number of Instances of the NFSD Server Daemon" and "5.7. Memory Limits on the Input Queue" in the NFS Howto. I'll describe how/where to set these in case of Debian.

Gtkdialog - complex GUI for scripts

"Gtkdialog is a small utility for fast and easy GUI building. It can be used to create dialog boxes for almost any interpreted and compiled programs which is a very attractive feature since the developer does not have to learn various GUI languages for the miscellaneous programming languages."

Gtkdialog is not just a simple xdialog replacement like Zenity. It allows creation of complex GUI with event-driven controlling logic. The GUI layout is described in XML files. Quite fancy. Smiling

Sed in Darwin (Leopard) is crippled in many ways

Today I had to face the fact that the sed in Darwin 9.4.0 (Mac OS X Leopard 10.5.4) lacks a lot of functionality.

How to copy files between hosts over the network using SSH + tar

It's quite simple, but I tend to forget some of the switches involved in the proper command line. So here it is:
tar -cf - /some/file | ssh host.name tar -xf - -C /destination

How to count the private memory used by a program

After reading the post on Understanding memory usage on Linux, I wanted a simple method to count the private bytes taken eg. by apache or php processes. Writing this is really not a big deal, but might be helpful for newbies ...

Automatized online backup of MySQL databases using LVM snapshots

This is again a script that people could write easily if they understood some shell scripting, but it is quite well implemented with logging and all and maybe spares a couple of minutes/hours of your time. Smiling

You should use it with crontab on a daily basis. For details take a look at the desc. of the MySQL backup script.

Redirecting standard output (stdout) to standard error (stderr)

Some might find this trivial, but it was not trivial to me. If you want to print something to stderr in a shell script, you can redirect the output of a command (eg. echo) to this stream (file handle or whatever):
echo "text" >&2

How to decide about a variable whether it contains a number or not

Let's suppose we have a variable named myvar. How do you decide (in a safe way!) in a standard POSIX shell (or in the almost equivalent /bin/sh of the Debian distros) whether it contains a number or not? Sounds pretty much trivial, not? Here's what I came up with:
mynumber=_
mynumber=$(($myvar)) 2> /dev/null
{ [ "$mynumber" = "_" ] && echo "Myvar is not a number."; } || echo "Myvar is a number."

How to read a local manpage file?

We all know the famous expression RTFM. The man command is our best friend. Smiling But what to do if you've just downloaded something and want to read a manpage that was bundled within? Here's the command to use:
groff -t -e -mandoc -Tascii filename | less

Syndicate content