To list the PIDs of all running process_name, instead of
To kill all running process_name, instead of
Problem with this script:
If the default route is missing when running this script to test an external host, the result will show the host is alive, along with the following ping error:
connect: Network is unreachable
Hence the (improved) version of ping script with Perl:
Embed perl in bash
I found it quite handy to use the above perl script in some of my gateway management bash scripts.
I have been a big fan of Gnome Desktop Environment due to its simplicity. But sometimes simplicity can lead to annoyance. For one, let’s look at the wallpaper dialog in GDE: suppose I spot a very interesting wallpaper on my friend’s PC and I would like to know where it’s located. I thought that’s easy: right-click on the desktop and choose Change Background, somewhere on the screen should tell you the full path of the wallpapers pool. Unfortunately it doesn’t tell you any information about all the wallpaper images, including the file paths. Interestingly enough, if want to add a new wallpaper to the pool, you click the Add button and browse to where the image file is located and click OK button (there exist other ways to add wall papers to the pool of course), meaning you know exactly where the wallpaper is located if you add one this way. But once you are done, unless you write down (or store it somewhere on your PC) about where the file is located, you lose track of the wallpapers completely.
Some of you might point out the locations of the wallpapers are all in the file ~/.gnome2/backgrounds.xml. True, all file locations are in there, but it won’t tell you which one is currently active. Plus, having to open that file (or something alike) in order to know the location of the wallpapers is a bit overkill for someone, say, absolute newbie. I understand that knowing exactly where the active wallpaper is located is not a common feature that everyone would ask for, but not providing a simple way to figure it out is indeed very annoying.
So far, I haven’t figure out a good solution to this problem.
I have developed this batch-processing script that’ll chop down files under a directory and process each group of files. Currently this bash script has the following features:
1) preview mode (option -p) lets you preview what commands will be executed
2) group files based on either
a) fixed number of files, for example, every 20 files
b) fixed bytes of file size sum, for example, every 10 MB
3) allow file list generation (which defaults to command find) to be customized by user
4) supports environment variable $VOL when the processing program is shell script (and is able to use environment variables)
For detail usage and examples, simply run bp.sh without any parameters.
View the code in (pretty) html format
View the raw codes in pure text format
[ Rename bp.sh.txt to bp.sh after downloading, the same step should be done for the following example scripts. ]
Example code 1: testbp.sh
Example code 2: testbp2.sh
Feedbacks or comments are welcome.
I would like to list a couple of mistakes I used to make often when using Linux commands:
1. Remove contents of a folder with rm
Let’s say I have a folder ~/data/docs and I want to empty it. There are hidden files (files that start with . ) along with files with regular names.
The wrong way:
the above command will remove all files and directories under ~/data/docs except the hidden ones.
The right way:
Note: the trailing 2>/dev/null suppresses the following error messages
An even better way
Note: using only the find command
will delete the folder ~/data/docs as well, hence the cd command.
2. Rsync contents of folder src with dest
The wrong way: (unless copying only non-hidden items is the goal)
Similar to the rm mistake. Using rsync this way will only copy non-hidden files and folders from src/ to dest/
The right way:
Be careful not to type this instead [ without the trailing slash after src ]:
as that will put folder src instead of the content of it under /path/to/dest, that is, after running the above command, the destination folder structure will have the following folder:
I prefer using method 2 because it’s simpler to construct and for ip addresses such as 220.127.116.114 (obvious an invalid one), using method 1 results in18.104.22.168 being matched. But method 2 will not mistakingly pick up that ip address.
Reference: Mastering Regular Expressions by Jeffrey E.F. Friedl.
Recently I replaced my ubuntu 9.04 with LinuxMint 8 which uses Grub2 as the boot loader and I found it quite annoying for the following reasons:
1) There is no more /boot/grub/menu.lst to edit, instead, any new boot entries should be inserted into /etc/grub.d/40_custom
2) Adding a new boot entry or modifying boot settings (such as default timeout value) requires an additional command in order for the new settings to become effective:
[ update-grub also works ]
3) Because of the above reasons, if the LinuxMint can’t boot due to some misconfiguration in the grub setting, it becomes harder to get it repaired since you run into the egg-and-chicken dilemma: you have to boot into LinuxMint in order to get grub2 repaired and updated [ which is exactly the reason I don’t like using boot loader lilo ]
4) The syntax has changed in grub2 for boot entries: among other changes, kernel is now replaced with linux, initrd is replaced with module (and module supports loading other things, this seems to be the only + point for grub 2)
All in all I was not impressed with the new “features” introduced by grub2 and as a result I downgraded it to grub using the other OS (Centos 5.4) on the same hard drive.