Monday, 8 December 2014

Using RSYNC to copy only certain files matching a pattern/wildcards in a directory tree in bash/linux

create this file:
if [ "$3" == "" ]
  echo "syntax:  $0 [pattern] [from_dir] [to_dir]"
  echo "example: $0 \"*.txt\" ./"
  exit 255

rsync -vtrla --progress --partial --prune-empty-dirs --include='*/' --include="$1" --exclude='*' "$2" "$3"

now you can do:
./rsync-only-files-matching "*.txt" source/dir/ target/dir/
  • because it's rsync, the trailing slash in the source dir tells it to copy the files (excluding hidden ones) in that directory. Omitting it means you'll copy the directory itself
  • You can omit the double quotes on the pattern if there are no files matching it in the current directory. It's just to prevent the shell from expanding it as a local path.

Thursday, 27 November 2014

What do to when cron refuses do run your Ruby script (using RVM and Bundler)

The reason this was happening to me was that I was using RVM, as well Bundler on a production server. This was the first time I used RVM in production, and I hoped it would run super smooth... Alas!
The main Sinatra web application was running perfectly, but the background script simply would not run, and there was no output either. Adding some debug statements in crontab revealed that all other operations ran perfectly both before and after the Ruby script.

Tuesday, 18 November 2014

How to make new files and directoris inherit group and permissions in GNU/Linux

~$ mkdir directory
~$ chmod 770 directory  # gives full permissions for owner and group, none to others
~$ chmod g+s directory  # makes new filed and dirs inherit group ownership
~$ chgrp grp directory  # changes group ownership to "grp"
~$ cd directory/
~/directory$ ls -la
total 8
drwxrws--- 2 usr grp 4096 Nov 18 07:42 .
drwxr-xr-x 6 usr usr 4096 Nov 18 07:42 ..

Monday, 10 November 2014

How to prevent Ubuntu from running all kinds of processes slowing the computer down at 7:30am

I like to work early in the morning, and have been pretty annoyed when my relatively slow Asus eee seemingly randomly ground almost to a complete halt for a few minutes every morning. I noticed eventually that this happened around 7:30, and I usually had to kill some processes, such as these, to get work done:
/usr/bin/python /usr/sbin/update-apt-xapian-index --update --quiet
/usr/bin/find / -ignore_readdir_race ( -fstype NFS -o -fstype nfs -o -fstype nfs

It turns out that anacron was set up (presumably by default) to run all the daily cron jobs (defined in /etc/cron.daily) at 7:30.

Saturday, 1 November 2014

Getting a network connection in Ubuntu 14.04 (Trusty) on a Dell Inspiron 6400 with Broadcom wired and wireless chipset


The computer had no wired or wireless connection.
When clicking the Network manager icon, the first line read No network devices available.
This was an ancient Dell Inspiron 6400 laptop with Broadcom BCM4311 wireless network adapter and Broadcom BCM4411 wired ethernet adapter. If your computer is not the same, this solution may not work.