*nix Lines

May 26

digging for library problems?

ldd `which [progname]`

The output will be a list of the shared libraries on the system that the program needs to run, as well as the missing libraries.

Sep 04

More dabbling around audio configuration

I have found the tools that come with the desktop environments to be fickle - so here are some pointers to figure things out from the command line

Step 0 - lspci (make sure it is even seen at a low level)

lspci -v

if not in there, you have a hardware or bios problem

Step 1 - aplay

aplay -l

(it’s a lower case L)

**** List of PLAYBACK Hardware Devices ****
card 0: VT82xx [HDA VIA VT82xx], device 0: ALC888 Analog [ALC888 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: VT82xx [HDA VIA VT82xx], device 1: ALC888 Digital [ALC888 Digital]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: System [ZP Hi-Fi Component System], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

Step 2 - find order

cat /proc/asound/modules

in my case it returns

 0 snd_hda_intel
 1 snd_usb_audio

Step 3 - set order

in slackware is it in /etc/modprobe.d/sound.conf

alias snd-card-1 snd-hda-intel
alias sound-slot-1 snd-hda-intel
alias snd-card-0 snd-usb-audio
alias sound-slot-0 snd-usb-audio

in debian based it might be in /etc/modprobe.d/alsa-base

options snd-usb-audio index=0
options snd-hda-intel index=1 

Sep 03

Memory jog: Crypto tools -

############################# # GNUPG ############################# 
# generate a keypair 
gpg --gen-key 
# export ones public key 
gpg --armor --output pubkey.txt --export 'My name' 
# send the key on the server (easier with kgpg)
gpg --send-keys 'My name' --keyserver hkp://subkeys.pgp.net 
# import someone else's key
gpg --import key.asc gpg --search-keys 'tnagy1024@gmail.com' --keyserver hkp://subkeys.pgp.net 
# encrypt a file 
gpg --encrypt --recipient 'tnagy1024@gmail.com' foo.txt 
# decrypt a file gpg --output foo.txt --decrypt foo.txt.gpg

Aug 31

Nice trick: number base conversion one liners using bc -

For those who needs quick help on number conversion between base-x to base-y, bc can lend a help here.

For example, what’s the hexadecimal form of 116?:

$ echo ‘obase=16; 116’ | bc

74

And what does binary 11010101 look in decimal?

$ echo ‘ibase=2; 11010101’ | bc

213

By doing below step, you directly convert binary 11010101 to hexadecimal:

$ echo ‘obase=16; ibase=2; 11010101’ | bc

D5

Note that “obase” must preced “ibase” in order to make a correct final result.

Mulyadi Santosa
Freelance Linux trainer
blog: the-hydra.blogspot.com

Memory Jog: bash control characters and special variables

| = pipe will take the first commands stdout as the second commands stdin. || = OR if first command is false, it will take the second.
|= = OR IS (mostly used in if statements)
&& = AND if first command is true, it will execute the second one.
! = NOT (mostly used in if and test statements)
!= = NOT IS (mostly used in if statements)
!$ = last commands last argument
= = IS (mostly used in if statements)
; = will separate 2 commands as if they were written on separate command lines
;; = end of a case function in a case statement. (see `case` further down)
$ = prefix to a variable like "$myvar"
$$ = PID of current process (PID == Process ID)
$0 = Shows program that owns the current process.
$# = Shows the number of arguments.
$? = Any argument (good to use in `if` statements)
$_ = All arguments
$* = All arguments
$@ = All arguments
# = remmed line, anything on a line after "#" will be overlooked by the script
{ = start braces (starts a function)
} = end braces (ends a function)
[ = start bracket (multiple-argument specifiers)
] = end bracket (multiple-argument specifiers)
@ = $@ is equivalent to "$1" "$2" etc. (all arguments)
* = wild card (* can substitute any number of characters)
? = wild card (? can substitute any single character)
" = quote
' = precise quote. (Will even include "'s in the quote)
` = command quote. (variable=`ls -la` doing $variable will show the dir list)
. = dot will read and execute commands from a file, ( . .bashrc )
& = and. as suffix to executed file makes it go to the background(./program &)
0> = stdin stream director
1> = stdout stream director
2> = stderr stream director
% = job character, %1 = fg job 1, %2 = fg job 2, etc.
>> = stream director append to a file
<< = stdin stream director, that appends. (cat > file << EOF; anything ; EOF)
< = stdin stream director
> = stream director that will start at the top of the file (in if statements < and > may be used as greater-t$
\ = back-slash, takes away any special meaning with a character

Aug 30

RSI prevention: pgrep

look up (pgrep) or signal (pkill) processes based on name and other attributes

pgrep [-flvx] [-d delimiter] [-n|-o] [-P ppid,…] [-g pgrp,…]
[-s sid,…] [-u euid,…] [-U uid,…] [-G gid,…]
[-t term,…] [pattern]

pkill [-signal] [-fvx] [-n|-o] [-P ppid,…] [-g pgrp,…]
[-s sid,…] [-u euid,…] [-U uid,…] [-G gid,…]
[-t term,…] [pattern]


key options:

-u by user

-f full command

-n /-o newest/oldest

-x exact

Aug 29

1 line download source for slackbuild

Slackbuilds are a lot like freeBSD ports (or slitaz receipts) - except they don’t download the source for you. So you do a lot of repetitive: download build, untar, change into directory, download source, run script, copy resulting package. Just did 20 of them and thoroughly annoyed, and if i want all the perl and python builds there’s dozens more!

1. the resulting package location you can resolve with a variable (OUTPUT to join ARCH which is also not set but much necessary)

2. The download / unzip can be done via rsync - as shared on the linuxquestions board:

/usr/bin/rsync -avz slackbuilds.org::slackbuilds/13.0/ /home/slackbuilds

So we are left with the get source, check notes, run script part - so I’ve been dusting my shell scripts to create a script which can take a list of names, find their directories, get the source (needs to be something in there for the sourceforge HTML redirect pages), and create a script that can be run to run all the slackbuilds in a row (dont believe in totally automating this part just yet)

First, write a one liner to get the url of the source file and run wget to get it

cat *.info | grep DOWNLOAD= |  awk '{split($0,a,"="); print a[2]}' | sed 's/"//g' | xargs wget

next i need a version which checks both for the 64bit and gets that instead (that should all be doable within the awk bit, if the DOWNLOAD_64= match contains something, use that, else use the DOWNLOAD=)

after that i can take a list of names and crawl the build tree to download all the files (such a boring thing to do manually)

Of course I suspect it would have taken me half the time to just do it in perl, and it would be easier in perl to generate a summary of any instructions plus a shell script to run the build.

Or i can continue to dust my shell and do a whole script. tomorrow.

do you have any idea how long it took me to refind the xargs trick? gnnnnnn! And I have a whole bash scripting book downstairs which probably would have helped in seconds

Aug 27

memory jog: Vim

Copy & Select Text aka Yank

v Visual - move to select the text you wish to handle.
+y Copy the selected text.
d Cut the selected text.
ggVG Select all

*NOTE: “+” represents shift.

Paste aka Put:

p Pastes the selection

Delete aka Cut:
*NOTE: in vim “delete” and “cut” is the same.

dw To delete from the cursor to the end of a word type.
d$ To delete from the cursor to the end of a line type.
dd To delete a whole line type.

Change & Replace

r and then the character which will replace the one under the cursor
cw To change from the cursor to the end of the word
c$ To change to the end of a line.

Undo:

u To undo previous actions. (lowercase u)
U To undo all the changes on a line. (capital U)
CTRL-R To undo the undo’s aka “Redo”

Search & Search and Replace aka “Find and Replace”

/someword [ENTER] This would search for “someword”.
n next
+n previous
:%s/old/new/gc Search & Replace with confirmation.

Execute External Commands from within Vim

!<command>
:!ls This would execute “ls” from Vim.

Aug 26

memory jog: command line wireless tools

basic configuration

iwconfig wlan0  
iwconfig wlan0 essid "mynetwork"
iwconfig wlan0 key XXXXXXXXXXXXXXXXXXXXXXXXXXX

ifconfig has options like: roaming, bssid, nwkey, wpa but they to set the card as an access point iirc

wpasupplicant for complex key operations

diagnostics

lsmod
ifconfig -a
iw wlan0 scan
iwlist wlan0 scanning
ifconfig wlan0 up scan

config files

on slackware: same as wired in /etc/rc.d/rc.inet1.conf

on freebsd, ifconfig string parameters in /etc/rc.conf

on slitaz

on ubuntu

Aug 25

ways to set the keyboard (in my case to swiss french layout)

console:

/usr/bin/loadkeys /usr/share/kbd/keymaps/i386/qwertz/fr_CH-latin1.map.gz

for x:

setxkbmap ch -variant fr