Monday, September 17, 2018

Simple bash "UUID" generator

If you need a UUID-like string in a bash script, e.g. for the message part boundary in an email, this is probably about as simple as you can get:

#!/bin/bash

MD5SUM=/usr/local/gnu/bin/md5sum
DATE=/usr/local/gnu/bin/date

MD5=$($DATE +'%s.%N'|$MD5SUM)

B1=${MD5:0:8};B2=${MD5:8:4};B3=${MD5:12:4};B4=${MD5:16:4};B5=${MD5:20:12}

BOUNDARY="$B1-$B2-$B3-$B4-$B5"

Wednesday, August 15, 2018

Using lftp to mirror sub directories.

lftp can nicely mirror sub directories... just do: mirror --use-pget-n=5

Wednesday, May 30, 2018

perl5/perlbrew/etc/bashrc: line 103: perlbrew: command not found

If you're getting /path/to/perl5/perlbrew/etc/bashrc: line 103: perlbrew: command not found Try checking to see you don't have a $HOME/.perlbrew/init file which points to an old version of perlbrew which has been deleted.

Say no to whichcraft

Interesting and useful history and alternatives to which command https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then/85250#85250

Tuesday, May 15, 2018

Lazy way to resort a table in SQL

When you have a query and you want to sort the output but the query is too complex to see what to sort on. (say your output column isn't a selected column, but rather generated data)

select
case
        when substring(t1.some_column, 1, 1) = '#' then rtrim(t1.some_column)
        when 'some_group' in ('group_a', 'group_b', 'group_c', 'group_d', 'group_e') then  '#' + rtrim(t1.some_column)
        else rtrim(t1.some_column)
end as 'op_col_1',
case
 when t1.ip_col_1 = 'a' then 'ant'
 when t1.ip_col_1 = 'b' then 'beetle'
 when t1.ip_col_1 = 'c' then 'centipede'
 else 'no_bugs'
end as 'op_col_2',
from table_one t1

You can wrap the whole lot in brackets and sort by the column order or the generated name:

select * from (
select
case
        when substring(t1.some_column, 1, 1) = '#' then rtrim(t1.some_column)
        when 'some_group' in ('group_a', 'group_b', 'group_c', 'group_d', 'group_e') then  '#' + rtrim(t1.some_column)
        else rtrim(t1.some_column)
end as 'op_col_1',
case
 when t1.ip_col_1 = 'a' then 'ant'
 when t1.ip_col_1 = 'b' then 'beetle'
 when t1.ip_col_1 = 'c' then 'centipede'
 else 'no_bugs'
end as 'op_col_2',
from table_one t1
) query_out
where op_col_1 like 'blah%'
order by op_col_2
or
order by 2

Thanks Chris!

Tuesday, April 24, 2018

Sybase column name and datatype of all columns in a table

SELECT syscolumns.name, systypes.name FROM sysobjects
JOIN syscolumns ON sysobjects.id = syscolumns.id
JOIN systypes ON systypes.type = syscolumns.type
AND systypes.usertype = syscolumns.usertype
WHERE sysobjects.name LIKE 'my_table'

https://stackoverflow.com/a/28940121/224625

Tuesday, October 31, 2017

Show seconds in ls -l output on Solaris 10

If you need to show the seconds (and year) in the output of ls -l on Solaris:


$ ls -le /path/to/file

Friday, August 26, 2016

Ardour4, JACK, ALSA... Rosegarden, qsynth etc...

When you install Ardour on a fresh Debian install you will probably find that the sound isn't working.

Here's what I did to get it going.

sudo aptitude install ardour

I also installed these.

sudo aptitude install Qtractor
sudo aptitude install audacity

I installed these 2 to convert mp3s to ogg so I could import them.
Qtractor lets you import mp3 but ardour doesn't

sudo aptitude install ffmpeg
sudo aptitude install dir2ogg


To control/configure jack....

sudo aptitude install jack-tools qjackctl

This lets JACK and Pulse talk to each other, otherwise they lock each other out.

sudo aptitude install pulseaudio-module-jack

I'm not sure if I needed this, but this was one step:

sudo aptitude install linux-image-4.6.0-1-rt-amd64

This was the key: https://ubuntuforums.org/archive/index.php/t-986080.html


I would bet you need to look at the Ardour mixer and route the Main Output channel to your soundcard outs.

In Ardour press Alt+M (to view the mixer) then at the bottom of the Main Output strip there should be a button labeled Output - click that, then add your soundcard outs to the appropriate channels in the dialog box that pops up.

There shouldn't be any issue with the format of your wav file as ardour will resample things for you (at a better quality rate than ProTools actually).

This issue could also stem from you not having JACK configured correctly. In Ardour's open dialog, if you haven't already started the JACK audio server, there will be a tab that says audio setup - this is Ardour's own JACK startup script. It should work fine by default, but you should probably read up on JACK and qJackCtl.

To get Rosegarden going I used this page: http://gauthampai.livejournal.com/62383.html
The key to that was installing the soundfont, and qsynth.

Once you've got it configured and working, you also need to start qsynth before Rosegarden and have it running the whole time Rosegarden is. If you restart qsynth you'll probably need to restart Rosegarden for it to reconnect.


Tuesday, February 02, 2016

Installing 7-Zip plugin in MobaXterm

I like MobaXterm http://mobaxterm.mobatek.net/

I like 7-Zip http://p7zip.sourceforge.net/
(In my previous version of this How-To I used 7-Zip for Windows from http://www.7-zip.org/ ) to open the downloaded archive, but now you can do it all from within mobaxterm.

To get 7-Zip working in MobaXterm I downloaded the 7-Zip package from a cygwin mirror... (find your closest one at https://cygwin.com/mirrors.html )

You can find the current version with this:
wget -qO- http://mirrors.kernel.org/sourceware/cygwin/x86/release/p7zip/ | sed -e 's/<[^>]*>//g'
Then download the version you want. e.g.:
wget -N http://mirrors.kernel.org/sourceware/cygwin/x86/release/p7zip/p7zip-15.14-2.tar.xz
You should now have this file in your current directory:
-rwxrwx---    1 Administ UsersGrp   1039440 Apr  5 05:12 p7zip-15.14-2.tar.xz
You can unpack the tar.xz with gnu tar:
tar xvf p7zip-15.14-2.tar.xz
You can then create the package using the p7zip from the unpacked tar file:
usr/lib/p7zip/7za.exe a p7zip.mxt3 -tZIP usr
Finally move the file you have created to C:\Program Files (x86)\Mobatek\MobaXterm Personal Edition
You will probably need to do that step from outside MobaXterm otherwise you won't have permission to write to the directory.

Then restart MobaXterm.

job done.

If you don't know where to find your home directory from Windows you can open it in Windows Explorer by doing:

$ open $PWD

from the command line in your home directory.


NB:
If you have trouble with the step creating the mxt3 file you can do it via Windows too:
Originally I opened the directory it created ( p7zip-15.09-1 ) in Windows Explorer and right clicked on the usr directory and chose 7-Zip -> Add to "usr.zip" (NB: Choose usr.zip, not usr.7z here)
This created a .zip file containing the usr directory.

I then renamed usr.zip to p7zip.mxt3

Wednesday, August 13, 2014

/etc/acct/holidays

In /var/adm/messages on Solaris:

Aug 13 02:30:16 hostname adm: [ID 702911 daemon.notice]
Aug 13 02:30:16 hostname last message repeated 4 times
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.notice] **********  SYSTEM ACCOUNTING STARTED Wed Aug 13 02:30:16 BST 2014  **********
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.notice]
Aug 13 02:30:16 hostname last message repeated 4 times
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.error]
Aug 13 02:30:16 hostname last message repeated 1 time
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.error] ************ ACCT ERRORS : see  /var/adm/acct/nite/log********
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.error]
Aug 13 02:30:16 hostname last message repeated 1 time

In /var/adm/acct/nite/log

***UPDATE /etc/acct/holidays WITH NEW HOLIDAYS***

Update /etc/acct/holidays to have 2037 for the year.

$ cat /etc/acct/holidays
* @(#)holidays  January 1, 2010
*
* Prime/Nonprime Table for UNIX Accounting System
*
* Curr  Prime   Non-Prime
* Year  Start   Start
*
  2037  0800    1800
*
* only the first column (month/day) is significiant.
*
* month/day     Company
*               Holiday
*
1/1             New Years Day
12/25           Christmas

https://hg.openindiana.org/upstream/illumos/illumos-gate/raw-file/afe390b9f1e0/usr/src/cmd/acct/lib/pnpsplit.c

/*
 * inithol - read from an ascii file and initialize the "thisyear"
 * variable, the times that prime and non-prime start, and the
 * holidays array.
 */
int
inithol()
{
...
 /* validate year */
 if(thisyear < 1970 || thisyear > 2037) {
  fprintf(stderr, "pnpsplit: invalid year: %d\n",
   thisyear);
  errflag++;
  break;
 }
...
}