Enabling SPDIF sound on Ubuntu with Dell Docking station

April 13th, 2009

Should you come across the same need, I just found a working solution, even if quite odd.

The trick to get it working is to go into sound settings and enable IEC958 Playback AC97-SPSA, checking that volume is set to… 0.

Magically sound will begin to flow out of the SPDIF interface.


Email this post Email this post

Bulk File Rename

March 24th, 2009

Situation:

I have multiple files with extension .sh.modified and I need to rename them all into .sh extension.

Solution:

for file in *.sh.modified; do mv ${file} ${file%sh.modified}.sh; done


Email this post Email this post

How to check for new files in a directory

March 21st, 2009

Made this small script for this purpose…

#!/bin/bash
#
# Script to check a directory and write in file the new files
# since last check.
#
# Written by RoarinPenguin (
roarinpenguin@rottigni.net) on
#
21 march 2009
# Released under GPL License
#
# You need to create a file called lastcheck.time in same
# directory of this script
#

ADMIN="change to administrator email address"
DIR2MON=/var/www/dir-clienti

> ./newfiles.list
echo "Last check for new files, done on "`date` >> ./newfiles.list
find $DIR2MON -maxdepth 5 -newer ./lastcheck.time >> ./newfiles.list
touch ./lastcheck.time


Email this post Email this post

Using variables in sed

March 10th, 2009

In a world of Perl, sed seems to be an archaic method of doing things reserved to the real brave geeks!

But sometimes sed does perfectly fantastic job, like it did for me few minutes ago… with some caveats.

My goal was to replace $i with the value of the variable, determined by the first part of the script:

for i in `seq 1 50`;

the problem was that I made rest of the cycle as follows:

do cat newtest.xml|sed –e ‘s/variable/$i/’ >> multifirewallimport.xml; done

and the result was that through all my file the word variable was replaced with the word $i.

What was wrong? Well… Googling for it I discovered the issue was in usage of single quote instead of double quote.

The correct form is:

for i in `seq 1 50`; do cat newtest.xml|sed -e "s/variable/$i/" >> multifirewallimport.xml; done


Email this post Email this post

Enabling root access to vsftpd

March 6th, 2009

It took me a while to figure out due to misleading information over the vast Internet suggesting to search for non existing /etc/vsftpd.users or something like this.

Thing you have to do is to edit /etc/ftpusers and remove root from there.


Email this post Email this post

How to check if LDAPS is really running on a server?

February 9th, 2009

Sometimes this is necessary since the server “appears” to be running (netstat -an|grep 636 returns port in LISTEN state, but the daemon behind is not operative because (for instance) the certificate has not been installed.

If this is the case, grab an openssl client and issue the following command:

openssl s_client host <address of the target host> –port 636 (this is LDAPS standard port)

If server does have valid certificate you should get answer like:

If it does not, you’ll get something like this:

image


Email this post Email this post

Assigning privileges to a user on MySQL DB

February 3rd, 2009

Quick and dirty commands from commandline:

mysql -u <user> -p<password>
mysql> CREATE DATABASE wordpress;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO ‘wpuser’@'localhost’ IDENTIFIED BY ‘dbpassword’;
mysql> SET PASSWORD FOR ‘wpuser’@'localhost’ = OLD_PASSWORD(’dbpassword’);
mysql> FLUSH PRIVILEGES;
mysql> quit;


Email this post Email this post

Scripting elegance: reading filenames containing spaces

February 3rd, 2009

You might need to do something with a list of files contained in a file… and maybe these file names include spaces, therefore using a standard

for i in `cat filename`
do
echo $i
done

does not work since it will consider every word as a single variable.

This second script does the job:

IFS=\$    ==> this sets the line separator as EOL
while read i    ==> this read variables separated by EOL and stores value in $i
do
echo $i    ==> this echoes the value of $i. Replace echo command with whatever you want to do with filenames
done < file-containing-the-list    ==> this ends the while do cycle and takes input from file where filenames are stored


Email this post Email this post

I don’t want that NIC to be probed

January 20th, 2009

Suppose you are on a Linux box with multiple NICs.

It happens that there is one of them that loads with a driver disturbing test/activity you’re doing and you want to exclude it from modprobe.

You should edit file /etc/modprobe/blacklist and add there the driver name used by the card you want to get rid of, as follows:

/etc/modprobe.conf

[snip]
blacklist 8139cp
blacklist 8139too
[snip]

The example above (no, you don’t have to add snips, it is just to show that this is part of a bigger file…) will avoid Linux to probe for Realtek based NICs.


Email this post Email this post

Bluetooth and headless Linux

January 11th, 2009

Ever wondered how to connect your linux box via bluetooth, for instance to allow file transfer with your phone?

I found some cool and working hints on the Net, reporting here below what worked for me.

  1. Connect your USB dongle
  2. Install what you need:
    apt-get install obexftp bluetooth
  3. Then you need to set the system to use a predefined PIN, since you have no console and very probably you would like to digit only from phone side to connect with this box.
    To do this, you need to edit file /etc/bluetooth/hcid.conf to change the following defaults:
    # Security Manager mode
    #   none – Security manager disabled
    #   auto – Use local PIN for incoming connections
    #   user – Always ask user for a PIN
    #
    security auto; <== this is set by default to user

    and
            # Default PIN code for incoming connections
            passkey "58336342"; <== this is set by default to 1234, not enough secure IMHO…

Now, back to cellular connections:

  1. Scan for cellular address:
    hcitool scan
    this will return the address of your device, like:
    magicbox:~# hcitool scan
    Scanning …
            00:17:E4:82:F4:64       RoarinPenguin
  2. Now we need to search the channel for file tranfers
    magicbox:~# sdptool browse 00:17:E4:82:F4:64      
    This will return all details about services provided by the phone:
    magicbox:~# sdptool browse 00:17:E4:82:F4:64
    Browsing 00:17:E4:82:F4:64 …
    Service Name: AVRCP Target
    Service Description: Audio Video Remote Control
    Service Provider: Symbian Software Ltd.
    Service RecHandle: 0×10000
    Service Class ID List:
      "AV Remote Target" (0×110c)
    Protocol Descriptor List:
      "L2CAP" (0×0100)
        PSM: 23
      "AVCTP" (0×0017)
        uint16: 0×100
    Profile Descriptor List:
      "AV Remote" (0×110e)
        Version: 0×0100
  3. Service RecHandle: 0×10001
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 1

    Service Name: Dial-Up Networking
    Service RecHandle: 0×10002
    Service Class ID List:
      "Dialup Networking" (0×1103)
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 2
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "Dialup Networking" (0×1103)
        Version: 0×0100

    Service Name: OBEX Object Push
    Service RecHandle: 0×10003
    Service Class ID List:
      "OBEX Object Push" (0×1105)
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 9
      "OBEX" (0×0008)
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "OBEX Object Push" (0×1105)
        Version: 0×0100

    Service Name: Hands-Free Audio Gateway
    Service RecHandle: 0×10004
    Service Class ID List:
      "Handfree Audio Gateway" (0×111f)
      "Generic Audio" (0×1203)
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 28
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "Handfree Audio Gateway" (0×111f)
        Version: 0×0101

    Service Name: Headset Audio Gateway
    Service RecHandle: 0×10005
    Service Class ID List:
      "Headset Audio Gateway" (0×1112)
      "Generic Audio" (0×1203)
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 29
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "Headset" (0×1108)
        Version: 0×0100

    Service Name: Imaging
    Service RecHandle: 0×10006
    Service Class ID List:
      "Imaging Responder" (0×111b)
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 15
      "OBEX" (0×0008)
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "Imaging" (0×111a)
        Version: 0×0100

    Service Name: SyncMLClient
    Service RecHandle: 0×10007
    Service Class ID List:
      UUID 128: 00000002-0000-1000-8000-0002ee000002
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 10
      "OBEX" (0×0008)
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "" (0×00000002-0000-1000-8000-0002ee000002)
        Version: 0×0100

    Service Name: OBEX File Transfer
    Service RecHandle: 0×10008
    Service Class ID List:
      "OBEX File Transfer" (0×1106)
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 11
      "OBEX" (0×0008)
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "OBEX File Transfer" (0×1106)
        Version: 0×0100

    Service Name: Nokia OBEX PC Suite Services
    Service RecHandle: 0×10009
    Service Class ID List:
      UUID 128: 00005005-0000-1000-8000-0002ee000001
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 12
      "OBEX" (0×0008)
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "" (0×00005005-0000-1000-8000-0002ee000001)
        Version: 0×0100

    Service Name: SyncML DM Client
    Service RecHandle: 0×1000a
    Service Class ID List:
      UUID 128: 00000004-0000-1000-8000-0002ee000002
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 13
      "OBEX" (0×0008)
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "" (0×00000004-0000-1000-8000-0002ee000002)
        Version: 0×0100

    Service Name: Nokia SyncML Server
    Service RecHandle: 0×1000b
    Service Class ID List:
      UUID 128: 00005601-0000-1000-8000-0002ee000001
    Protocol Descriptor List:
      "L2CAP" (0×0100)
      "RFCOMM" (0×0003)
        Channel: 14
      "OBEX" (0×0008)
    Language Base Attr List:
      code_ISO639: 0×454e
      encoding:    0×6a
      base_offset: 0×100
    Profile Descriptor List:
      "" (0×00005601-0000-1000-8000-0002ee000001)
        Version: 0×0100

  4. The interesting channel for us is Obex File Transfer, thus 11. Let’s browse what telefone has to offer:

    obexftp -b  00:17:E4:82:F4:64 -c / -l

    This command will access the cellular of the given address the "/" (root) directory and will list its contents

Now, once could ask how to send files to the mentioned box. Well, so far I have discovered how to “pull” them from the box from the phone using obexftp command as follows:

obexftp -b 00:17:E4:82:F4:64 -c /<path_on_the_phone> -g picture1.jpg

There should be another way to put the box in listening mode through rfcomm command, but that’s food for another article ;) since I have first to read and “digest” articles like this one


Email this post Email this post