Category: Linux

How to recursively delete files matching a pattern

By , 2011-09-13 09:45

cd to the folder, run :

$ find . -name '*attach*' | xargs rm

where attach is the keyword present in all filenames to delete.

3 monitors and Updated xorg mesa drivers for Ubuntu Natty

By , 2011-09-09 14:34

I’m currently running Ubuntu Natty as my primary OS at work.

My setup is a Precision T3500 workstation that came with two NVIDIA Quadro cards which were a nightmare for Linux support. I heard that ATI cards supported 3 monitors on one card, as long as one of them was DisplayPort. I saw a cheap Radeon HD 5450 on sale for about $40, so I picked it up only to notice that it had an HDMI port instead of DisplayPort. I figured I’d try it anyway and was surprised to find that with the open-source radeon driver, 3 monitors work! One is connected by VGA, one HDMI and one DVI.

I had, however been experiencing random X crashes, and I suspect the problem was with the radeon driver.

Currently testing out some updated xorg drivers found at:

http://phoronix.com/forums/showthread.php?50038-Updated-and-Optimized-Ubuntu-Free-Graphics-Drivers

 

My system specs:

$ sudo lshw -short
H/W path         Device      Class       Description
====================================================
                             system      Precision WorkStation T3500 ()
/0                           bus         09KPNV
/0/0                         memory      64KiB BIOS
/0/400                       processor   Intel(R) Xeon(R) CPU           W3530  @ 2.80GHz
/0/400/700                   memory      256KiB L1 cache
/0/400/701                   memory      1MiB L2 cache
/0/400/704                   memory      8MiB L3 cache
/0/1000                      memory      14GiB System Memory
/0/1000/0                    memory      2GiB DIMM DDR3 1333 MHz (0.8 ns)
/0/1000/1                    memory      2GiB DIMM DDR3 1333 MHz (0.8 ns)
/0/1000/2                    memory      2GiB DIMM DDR3 1333 MHz (0.8 ns)
/0/1000/3                    memory      4GiB DIMM DDR3 1333 MHz (0.8 ns)
/0/1000/4                    memory      4GiB DIMM DDR3 1333 MHz (0.8 ns)
/0/1000/5                    memory      DIMM DDR3 Synchronous [empty]
/0/100                       bridge      5520/5500/X58 I/O Hub to ESI Port
/0/100/1                     bridge      5520/5500/X58 I/O Hub PCI Express Root Port 1
/0/100/1/0       eth0        network     82574L Gigabit Network Connection
/0/100/3                     bridge      5520/5500/X58 I/O Hub PCI Express Root Port 3
/0/100/3/0                   display     Cedar PRO [Radeon HD 5450]
/0/100/3/0.1                 multimedia  Manhattan HDMI Audio [Mobility Radeon HD 5000 Series]
/0/100/7                     bridge      5520/5500/X58 I/O Hub PCI Express Root Port 7
/0/100/14                    generic     5520/5500/X58 I/O Hub System Management Registers
/0/100/14.1                  generic     5520/5500/X58 I/O Hub GPIO and Scratch Pad Registers
/0/100/14.2                  generic     5520/5500/X58 I/O Hub Control Status and RAS Registers
/0/100/1a                    bus         82801JI (ICH10 Family) USB UHCI Controller #4
/0/100/1a.1                  bus         82801JI (ICH10 Family) USB UHCI Controller #5
/0/100/1a.2                  bus         82801JI (ICH10 Family) USB UHCI Controller #6
/0/100/1a.7                  bus         82801JI (ICH10 Family) USB2 EHCI Controller #2
/0/100/1b                    multimedia  82801JI (ICH10 Family) HD Audio Controller
/0/100/1c                    bridge      82801JI (ICH10 Family) PCI Express Root Port 1
/0/100/1c.5                  bridge      82801JI (ICH10 Family) PCI Express Root Port 6
/0/100/1c.5/0    eth1        network     NetXtreme BCM5761 Gigabit Ethernet PCIe
/0/100/1d                    bus         82801JI (ICH10 Family) USB UHCI Controller #1
/0/100/1d.1                  bus         82801JI (ICH10 Family) USB UHCI Controller #2
/0/100/1d.2                  bus         82801JI (ICH10 Family) USB UHCI Controller #3
/0/100/1d.7                  bus         82801JI (ICH10 Family) USB2 EHCI Controller #1
/0/100/1e                    bridge      82801 PCI Bridge
/0/100/1f                    bridge      82801JIR (ICH10R) LPC Interface Controller
/0/100/1f.2      scsi0       storage     82801JI (ICH10 Family) SATA AHCI Controller
/0/100/1f.2/0    /dev/sda    disk        250GB ST3250318AS
/0/100/1f.2/0/1  /dev/sda1   volume      101MiB Linux filesystem partition
/0/100/1f.2/0/2  /dev/sda2   volume      4102MiB Linux swap volume
/0/100/1f.2/0/3  /dev/sda3   volume      20GiB EXT4 volume
/0/100/1f.2/0/4  /dev/sda4   volume      208GiB EXT4 volume
/0/100/1f.2/1    /dev/sdb    disk        1500GB WDC WD15EARS-00M
/0/100/1f.2/1/1  /dev/sdb1   volume      499GiB Data partition
/0/100/1f.2/1/2  /dev/sdb2   volume      897GiB Data partition
/0/100/1f.2/2    /dev/cdrom  disk        DVD-ROM TS-H353C
/0/100/1f.2/3    /dev/cdrw   disk        DVD+-RW TS-H653F
/0/100/1f.2/3/0  /dev/cdrw   disk        
/0/100/1f.3                  bus         82801JI (ICH10 Family) SMBus Controller

Removing PulseAudio from Ubuntu 11.04

By , 2011-08-18 14:58

PulseAudio, as usual, has been annoying me.

This time, it’s because it’s blocking the S/PDIF passthrough via HDMI from XBMC.

I found a great tutorial on how to disable it at http://www.jeffsplace.net/node/12.

However for some reason I had no sound from the TV. That’s because the default device for ALSA is the analog audio output rather than the HDMI port. To fix this, run aplay -l in terminal to determine the card ID for the HDMI out.

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 0: ALC662 rev1 Analog [ALC662 rev1 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Then, create a ~/.asoundrc file with the following:

pcm.!default "plughw:0,3"

Where 0 is your card ID and 3 is the device ID found from the aplay -l.

Now all apps should be able to play audio through ALSA/HDMI.

 

yer -ao alsa -ac hwdts -vo vdpau qgh_dts.dts

Configuring multiple static IP interfaces in Arch Linux (netcfg)

By , 2011-06-22 14:29

Being a long-time Ubuntu/Debian user, I’m used to editing the good ol’ /etc/network/interfaces file to configure network interfaces.

Recently, trying Arch Linux, I discovered that networking isn’t always that simple.

Most basic system parameters in Arch are configured in the /etc/rc.conf file. However, that file is limited to configuring one static wired ethernet connection.

In order to configure multiple interfaces, you need to install the netcfg package and create profiles for each NIC in /etc/network.d :

There are some examples provided, however none of them mention how to set a custom netmask or multiple DNS servers. So here are my two network profiles:

interface 1 (/etc/network.d/interface1-static)

CONNECTION='ethernet'
DESCRIPTION='Static IP WAN'
INTERFACE='eth0'
IP='static'
ADDR='172.32.24.108'
GATEWAY='172.32.24.1'
DNS=('172.16.24.1' '172.16.24.3')

interface 2

CONNECTION='ethernet'
DESCRIPTION='Static IP LAN'
INTERFACE='eth1'
IP='static'
ADDR='192.168.2.80'
NETMASK='255.255.254.0'

Once the profiles are created, go back to the /etc/rc.conf and make them activated at boot. The values for the NETWORKS array are the two files previously created in /etc/network.d:

# Enable these netcfg profiles at boot-up. These are useful if you happen to
# need more advanced network features than the simple network service
# supports, such as multiple network configurations (ie, laptop users)
#   - set to 'menu' to present a menu during boot-up (dialog package required)
#   - prefix an entry with a ! to disable it
#
# Network profiles are found in /etc/network.d
#
# This requires the netcfg package
#
NETWORKS=(interface1-static interface2-static)

# -----------------------------------------------------------------------
# DAEMONS
# -----------------------------------------------------------------------
#
# Daemons to start at boot-up (in this order)
#   - prefix a daemon with a ! to disable it
#   - prefix a daemon with a @ to start it up in the background
#
# If something other takes care of your hardware clock (ntpd, dual-boot...)
# you should disable 'hwclock' here.
#
DAEMONS=(hwclock syslog-ng net-profiles sshd netfs crond dbus @cups kdm)

Setting up rsync to mirror music library

By , 2011-04-06 21:04

Just threw together a quick rsync client-server setup for syncing my music library between to computers.

on one computer:

/etc/rsyncd.conf:

max connections = 2
log file = /var/log/rsync.log
timeout = 300

[music]
comment = Music Share
path = /path/to/music
read only = no
list = yes
uid = somebody
gid = somegroup
auth users = somebody
secrets file = /etc/rsyncd.secrets

On the client:

rsync --delete -azvv /path/to/local/music [email protected]::music

Also remember to check firewall settings, and run the rsync daemon as a user “somebody” that has access to write in the rsync’d folder.

And don’t forget to enable the rsync daemon in /etc/default/rsync

RSYNC_ENABLE=true

Copy files with progress

By , 2011-01-12 11:08
$ rsync -WavP src.file dst.file

Make Deluged allow other users to touch downloaded files

By , 2010-12-12 03:57

By default, deluged on Arch creates files as -rw-r–r–. I want -rw-rw-r– so that other non-daemon regular users have access to modify and delete the downloaded files. The fix is to add the non-deluge users to the “deluge” group (125), then add umask 002 to the “login” process of the daemon. So, in /etc/rc.d/deluged:

stat_busy "Starting Deluge Daemon"
[[ -z $PID ]] && su -l -s /bin/sh -c "umask 002 && /usr/bin/deluged >/dev/null" $DELUGE_USER

Redirecting a port to another host on same LAN using iptables

By , 2010-11-27 22:53

I have a strange situation where I want to redirect a specific port on one host to another host. That is, traffic to 192.168.1.100:8080 => 192.168.1.101:8080.

Found the answer on LQ forums.

iptables -A PREROUTING -t nat -p tcp -d 192.168.1.100 --dport 8080 -j DNAT --to-destination 192.168.1.101
iptables -A POSTROUTING -t nat -p tcp -d 192.168.1.101 --dport 8080 -j SNAT --to-source 192.168.1.100

Don’t ask me why this works. It just does. Well, the first line makes sense, but I have no idea what the second is doing.

After looking at the rule in Webmin, I think I figured it out.

  1. When a packet arrives at this computer, if protocol is TCP and destination is 192.168.1.100/32 (local IP) and destination port is 8080 then Destination NAT (change destination IP) to 192.168.1.101
  2. When a packet leaves this computer, if protocol is TCP and destination is 192.168.1.101/32 and destination port is 8080 (as would be the case for any packet modified by the above rule), then Source NAT (change source IP) to 192.168.1.100. (This ensures that the remote host .101 returns any packets via this computer, .100, rather than simply attempting to send them to the original requesting host.)

Update: This even works on an OpenVZ container! Just need to enable iptables nat in the vz config on the hardware node (VM host) [source].

nano /etc/vz/vz.conf

Then do Control W and SEARCH for IPTABLES

Comment out (by adding a # symbol to the line ) the current IPTABLES= line

and then copy/paste and add this line directly underneath the line you just commented out.

IPTABLES="ipt_REJECT ipt_recent ipt_owner ipt_REDIRECT ipt_tos ipt_TOS ipt_LOG ip_conntrack ipt_limit ipt_multiport iptable_filter iptable_mangle ipt_TCPMSS ipt_tcpmss ipt_ttl ipt_length ipt_state iptable_nat ip_nat_ftp"

It is important to make sure this is all in 1 line and that it does not wrap.

Now Control-S and save – overwriting the current file.

Finally do an /etc/init.d/vz restart
to restart openVZ.

Crontab

By , 2010-11-10 12:13

A handy, colourful guide to configuring cron, the *nix task scheduler.

Stolen from: http://www.notesbit.com/index.php/scripts-unix/crontab-quick-complete-reference-setting-up-cronjobs-in-unix-and-linux/

Configuring PBXinaflash, my way

By , 2010-10-24 22:16

Setting up a PBXinaflash with a cheap Wildcard X100p card. A bit rough; for future reference.

Part 1: Initial setup and dahdi config

  1. Installed pbxinaflash (Bronze, Asterisk 1.6)
  2. set passwords using passwd-master script
  3. Enable ICMP ping in iptables.
  4. Run dahdi_genconf -v
  5. Run dahdi_cfg -v
  6. Add #include /etc/asterisk/dahdi-channels.conf
    to /etc/asterisk/chan_dahdi.conf
  7. At this point, asterisk should answer calls from the PSTN and play a “not in service” message.
  8. Next step is probably to edit /etc/asterisk/dahdi-channels.conf and set context to from-zaptel to be able to assign a DID using the FreePBX web GUI.

Part 2: Adding SIP trunk

  1. PEER Details:
    username=14165551212
    type=peer
    secret=s3cr3t
    host=voip.voipprovider.net
    dtmfmode=auto
  2. USER Details (not sure what’s necessary here, probably some of this shouldn’t be here)
    username=14165551212
    type=peer
    secret=s3cr3t
    qualify=no
    promiscredir=yes
    nat=yes
    language=en
    insecure=very
    host=voip.voipprovider.net
    fromuser=14165551212
    fromdomain=voip.voipprovider.net
    dtmfmode=auto
    disallow=h263&h263p
    context=from-trunk
    canreinvite=no
  3. In System Admin> Asterisk SIP settings page, change useragent and activate NAT/external IP options

Part 3: Fax Config

  1. Installed Fax Configuration module from “Module Admin”. Configure destination email.
  2. Installed Free Fax for asterisk using license obtained from Digium
  3. Add a “Misc destination” for System Fax to extension 666
  4. Enable Fax detection on inbound route. Set destination to Misc destination created in step 2
  5. Further reading: fax_for_asterisk_admin_manual, http://bestof.nerdvittles.com/applications/fax/ and http://nerdvittles.com/?p=237. Didn’t end up using the extension created by the script, but perhaps the rpms installed are necessary.
  6. Finally, Web fax for Asterisk : http://www.csrdu.org/nauman/2010/10/18/web-fax-for-asterisk/

Custom theme by me. Based on Panorama by Themocracy