printf “%q ” in bash, to escape arguments

I learned a useful trick with the bash shell today.

We can use printf “%q ” to escape arguments to pass to the shell.

This can be useful in combination with ssh, in case you want to pass arguments containing shell special characters or spaces. It can also be used with su -c, and sh -c.

The following will run a command exactly on a remote server:

sshc() {
        remote=$1 ; shift
        ssh "$remote" "`printf "%q " "$@"`"
}

Example:

sshc user@server touch "a test file" "another file"
Posted in Uncategorized | Leave a comment

job control in the shell

Job control is a basic feature of popular UNIX and Linux shells, such as “bash”.
It can be very useful, so I thought I’d make a little tutorial on it…

^C    press Ctrl-C to interrupt a running job (you know this one!)
^\    press Ctrl-\ (backslash) to QUIT a running job (stronger)
^Z    press Ctrl-Z to STOP a running job, it can be resumed later
jobs  type jobs for a list of stopped jobs (and background jobs)
fg    type fg to continue a job in the foreground
bg    type bg to continue a job in the background
kill  kill a job, e.g. kill %1, or kill -KILL %2
wait  wait for all background jobs to finish

You can also use fg and bg with a job number, if you have several jobs in the list.

You can start a job in the background: put an &-symbol at the end of the command. This works well for jobs that write to a file, but not for interactive jobs. Things might get messy if you have a background job that writes to the terminal.

If you forget the % with kill, it will try to kill by process-id instead of job number.  You don’t want to accidentally kill PID 1!

An example:

vi /etc/apache2/vhosts.d/ids.conf
^Z
jobs
find / >find.out &
jobs
fg 2
^Z
jobs
bg 2
jobs
kill %2
fg
Posted in Uncategorized | Leave a comment

Fight Back against universal surveillance (aka Big Brother)

Today, FEBRUARY 11TH 2014, is “the day we fight back” against universal surveillance by our governments, and specifically the NSA (aka Big Brother).  Please add your voice to this protest, and add their black banner to your site/s.

https://thedaywefightback.org/

P.S. It seems that wordpress.com would charge me $30 to change the background colour of my page.  This is absurd, I will have to look for or likely make a better blog system.

Posted in Uncategorized | 2 Comments

svn ignore dammit

“Thank-you” svn for such a hideous, bogus and difficult way to ignore files.

So I wrote a script svn-ignore-all:

#!/bin/sh

# svn-ignore-all

# usage: 
#   1. run svn status to see what is going on at each step 
#   2. add or commit all files that you DO want to have in svn
#   3. remove any random files that you don't want to svn:ignore
#   4. run this script to svn:ignore everything marked '?' in output of `svn status`

svn status |
grep '^?' |
sed 's/^? *//' |
while read f; do
    d=`dirname "$f"`
    b=`basename "$f"`
    ignore=`svn propget svn:ignore "$d"`
    if [ -n "$ignore" ]; then
        ignore="$ignore
"
    fi
    ignore="$ignore$b"
    svn propset svn:ignore "$ignore" "$d"
done

Also, to ignore specific list of files / pathnames, we can use this variant svn-ignore. I guess svn-ignore-all should really be like xargs svn-ignore.

#!/bin/sh

# svn-ignore

# usage:
#   svn-ignore file/to/ignore ...

for f; do
    d=`dirname "$f"`
    b=`basename "$f"`
    ignore=`svn propget svn:ignore "$d"`
    if [ -n "$ignore" ]; then
        ignore="$ignore
"
    fi
    ignore="$ignore$b"
    svn propset svn:ignore "$ignore" "$d"
done

One more thing: I tend to pollute my svn checkouts with many random files. When it’s time to commit, I move those files into an ‘old’ subdirectory, and tell svn to ignore ‘old’.

Also posted here:  http://stackoverflow.com/questions/116074/how-to-ignore-a-directory-with-svn/19240497#19240497

Posted in Uncategorized | Leave a comment

Image | Posted on by | Leave a comment

9 reasons to love Pandora

Laptops and phones can be good, and do have some advantages …
but here are 9 reasons I love my Pandora:

 - fits in pocket                (2)
 - great gaming controls     (1) (2)
 - full ASCII+ keyboard      (1)     (3)
 - superb audio              (1) (2) (3)
 - excellent battery life        (2)
 - 2 x SD cards & USB        (1) (2) (3)
 - full open GNU/Linux OS    (1)     (3)
 - indie hardware project    (1) (2) (3)
 - great community & devs            (3)

(1) few if any phones have this
(2) few if any laptops have this
(3) few if any other pocket gaming boxes have this

pandora

That’s 6 ways a Pandora beats a phone, 6 ways it beats a laptop, 6 ways it beats other pocket gaming boxes. And 3 ways it beats all of the above.

Few if any other devices can score more than 3/9, on this list of very desirable features.

Pandora is elite and unique!

Posted in Uncategorized | 3 Comments

Don’t Feed The Trolls

Don’t Feed The Trolls

a maxim for life

Posted in Uncategorized | 2 Comments