Saturday, 27 August 2016

Mounting directory on server automatically at startup using sshfs in fstab

If you have a directory on a server, whether it's your home directory or something else, that you wish to be mounted automatically when you start your computer, this is how to do it:

Preparation:
Install sshfs:
$ sudo apt-get -y install sshfs

Friday, 10 April 2015

Fix incorrect file date/time and EXIF data on images from digicam

I noticed about 2 months late that the data on my digital camera was off by many years. As I use the file's last modification time to rename all images and videos to include the date in the file name, this was very impractical, and very annoying. The following fixed it all.

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:
rsync-only-files-matching:
#!/bin/bash
if [ "$3" == "" ]
then
  echo "syntax:  $0 [pattern] [from_dir] [to_dir]"
  echo "example: $0 \"*.txt\" ./ 192.168.1.100:/home/user/target_dir/"
  exit 255
fi

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/
i
Note: 
  • 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

Symptom:

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.

Saturday, 27 July 2013

Install Google Chrome in Ubuntu using Google's repositories

This is mostly a note to myself to save a minute of searching every time I need it:
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update
sudo apt-get install -y google-chrome-stable