Nick's Tech Blog: linux

Pages

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, August 17, 2012

Use sed to remove '^M' characters from a file

Simple stuff, this post is here more as a reference than anything.

Problem

Windows puts '^M' characters throughout text files. I want to remove them.

Solution

The following commands will strip out the '^M' characters, and put the contents into a new file, then overwrite the original file.
sed -e s/^M//g oldfile.txt > newfile.txt
mv newfile.txt oldfile.txt
To get the '^M' character, type Ctrl+V,Ctrl+M

Monday, September 26, 2011

Fedora > libfontconfig.so.1: cannot open shared object file: No such file or directory

Problem

Received the following exceptions (seperately) when attempting to run a java program on Fedora 15 amd64.

/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
...
libstdc++.so.5: cannot open shared object file: No such file or directory
...
Exception in thread "main" java.lang.UnsatisfiedLinkError: /some/directory/libmawt.so: libXext.so.6: cannot open shared object file: No such file or directory
...
libfontconfig.so.1: cannot open shared object file: No such file or directory


and so on.

Solution

Obviously a couple of dependencies were missing. To find out which package/s you need to install to fix a missing dependency, use "yum provides <missing_file>".
e.g.
# yum provides libfontconfig.so.1
fedora/metalink |  21 kB     00:00    
jenkins |  951 B     00:00    
updates/metalink |  12 kB     00:00    
fontconfig-2.8.0-3.fc15.i686 : Font configuration and customization library
Repo        : fedora
Matched from:
Other       : libfontconfig.so.1

Then install the packages...
e.g.
# yum install fontconfig

Repeat for all missing files.

Thursday, September 22, 2011

Fedora > java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment

Problem 

The following exception was encountered when running a java program on Fedora:
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment

Assumptions: you know what an xserver is.

Solution

Basically, the java program is trying to access the xserver, and can't.

If it should be accessing the xserver, make sure the xserver is started/running:
  • e.g. ps -ef | grep Xvfb
If it shouldn't be accessing an xserver, make sure the "DISPLAY" environment variable is unset:
  • unset DISPLAY

See also:
Fedora > install Xvfb as a service

Ubuntu > Filter directory /usr/lib/cups/filter for printer "<yourprinter>" is not owned by root.

Problem

You receive the following error status message for a printer, once it is installed (e.g. in the "Print" window).

Filter directory /usr/lib/cups/filter for printer "" is not owned by root. 

You may also see "cups-insecure-filter". 

Solution

Execute the following commands, to change ownership back to root. 

  1. sudo chown -hR root:root /usr/lib/cups/filter/* 
  2. sudo chown -hR root:root /usr/lib/cups/backend/* 
  3. service cups restart 

Your printer should now no longer display the message. (May require closing and reopening the "Print" window). 

See also:
https://bugs.launchpad.net/ubuntu/+source/cups/+bug/436544

Fedora > install Xvfb as a service

Problem

I required Xvfb to be installed, and running as a service on a server.

Assumptions: you know how to use chkconfig, yum, vi and chmod.

Solution
  1. yum install xorg-x11-server-Xvfb
  2. vi /etc/init.d/xvfbd (copy contents below into the file, and save it)
  3. chmod 755 /etc/init.d/xvfbd (now we have a service)
  4. chkconfig --add xvfbd
  5. chkconfig --level 2345 xvfbd on

You can now start your service with:
sudo service xvfbd start

Check it's running:
ps -ef | grep Xvfb

Check it's listed to startup automatically for runlevels 2,3,4,5:
chkconfig --list


/etc/init.d/xvfbd

#!/bin/bash
#
# description: Xvfb server
#


# Get function from functions library
. /etc/init.d/functions


# Start the service Xvfb
start() {
        echo -n "Starting Xvfb server: "
        /usr/bin/Xvfb &
        ### Create the lock file ###
        touch /var/lock/subsys/Xvfb
        success $"Xvfb server startup"
        echo
}


# Restart the service Xvfb
stop() {
        echo -n "Stopping Xvfb server: "
        killproc Xvfb
        ### Now, delete the lock file ###
        rm -f /var/lock/subsys/Xvfb
        echo
}


### main logic ###
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status Xvfb
        ;;
  restart|reload|condrestart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac


exit 0

See also:
http://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

Friday, September 16, 2011

Ubuntu > Install Canon Pixma MX870 i386 drivers on amd64

Problem

Canon only provide i386 drivers for the PIXMA MX870 All-In-One Printer on their Australian website.

These work fine with amd64, but just need the scripts to be tweaked to allow it (very easy to do).

Solution

Ensure you have the latest versions for the following applications:

$ apt-show-versions | grep -E "libcups2|libcupsys2|libc6|libpopt0"
e.g.
libc6/natty uptodate 2.13-0ubuntu13
libc6-dev/natty uptodate 2.13-0ubuntu13
libc6-i386/natty uptodate 2.13-0ubuntu13
libcups2/natty-security uptodate 1.4.6-5ubuntu1.4
libpopt0/natty uptodate 1.16-1


Follow these steps:
  1. Download the MX870 series IJ Printer Driver Ver. 3.30 for Linux (debian Packagearchive)
  2. Extract the cnijfilter-mx870series-3.30-1-i386-deb.tar.gz into a directory
    1. Nautilus > right-click > Extract Here
    2. Command line > tar -xvzf cnijfilter-mx870series-3.30-1-i386-deb.tar.gz -C /your/target/dir
  3. Comment out the "i686" lines in the <extracteddir>/install.sh, as per the instructions here.
  4. Update all <extracteddir>/packages/*.deb packages by running repackage.sh (see below), and removing the line beginning with "Dependency: ..." during the "vi" step.
    1. e.g. ./repackage.sh <package>.deb
  5. Run <extracteddir>/install.sh


repackage.sh
#!/bin/bash
PACKAGE=${1}
dpkg -x $PACKAGE common
dpkg --control $PACKAGE
vi DEBIAN/control
cp -a DEBIAN/ common/
dpkg -b common $PACKAGE
rm -rf common DEBIAN


See also:
https://bugs.launchpad.net/ubuntu/+source/cups/+bug/701856/comments/20
http://ubuntuforums.org/showthread.php?t=1475336

Wednesday, September 14, 2011

Ubuntu Unity > remove Rhythmbox from the sound menu

Problem

Ubuntu 'Natty' 11.04
There's no (obvious) way to remove rhythmbox from the sound menu in unity.

Solution

According to the documents on the ubuntu wiki, rhythmbox must be removed by using gsettings. Execute the following in your console:

gsettings set com.canonical.indicator.sound blacklisted-media-players "['rhythmbox']"

See: https://wiki.ubuntu.com/SoundMenu#Music_player_integration

Sunday, September 11, 2011

Fedora > WARNING: / partition has insufficient space to install the items selected

Problem

I received the following error, when installing an application on Fedora 15 (Tibco TRA as it happens).

WARNING: / partition has insufficient space to install the items selected.
XXX MB additional space would be needed to install the selected items.


Solution

Create a temp directory that can hold the amount of space required to install the application (e.g. /root/tmp).

Then append the following parameter on to your installation command.
-is:tempdir /root/tmp

See also:
http://publib.boulder.ibm.com/infocenter/iisinfsv/v8r1/index.jsp?topic=/com.ibm.swg.im.iis.productization.iisinfsv.install.doc/topics/iisri_verify_disk_space.html

Friday, September 9, 2011

Fedora > /bin/sh: bad interpreter: Permission denied

Problem

Received the following error message when attempting to install an application, in Fedora 15, where the current working directory is /tmp/somedir.
/bin/sh: bad interpreter: Permission denied

Solution

Security on Fedora/RHEL blocks executing scripts from /tmp. The solution/workaround is to move the directory to my homedrive, and run it from there instead.

http://www.velocityreviews.com/forums/t9645-bash-firefox-installer-bin-sh-bad-interpreter-permission-denied.html

Tuesday, August 23, 2011

Linux > tag files in a directory by directory name

Work in progress...


#!/bin/bash
#
# "tagdirs.sh"
#
# Simple script which iterates over the first level folders in a given directory,
# and tags the files in those subdirectories with the parent folder's name.
#
# Usage: ./tagdirs.sh
#
# N.B. Requires 'tracker-tag'.
#

# The folder to iterate over.
FOLDER=$1

# Check param is a directory...
if [ -d "${1}" ] ; then
echo "Processing directory '${1}'..."
else
echo "Error: bad argument. Expected a valid directory name for the first argument"
echo "Bad directory name = ${1}"
exit 1
fi

(
IFS=$'\n'
# For each directory...
for dir in $(find $FOLDER -maxdepth 1 -mindepth 1 -type d); do
# Strip directory to folder name only...
tag=${dir##*/}
# For each file in the directory...
for file in $(find $dir -maxdepth 1 -mindepth 1 -type f); do
echo "Adding tag '${tag}' to file '${file}'...";
tracker-tag --add="${tag}" "${file}"
done
done
)

exit 0

Monday, August 22, 2011

Stream content from Ubuntu to an Xbox360

Problem

I wanted to setup Ubuntu (11.04), so that I could access content from an Xbox360 using DLNA

Solution

  1. Open "Ubuntu Software Center" and install "rygel"
  2. Also install the additional "Tracker plugin" (only)
  3. Follow the steps under Helper Scripts (requires sqlite3)
Rygel can now be started from the terminal by executing "rygel".
    Movies/Pictures/Video's tagged in nautilius will be displayed (right click on the file and tag).

    See also:
    http://live.gnome.org/Rygel
    http://en.wikipedia.org/wiki/Digital_Living_Network_Alliance

    Installing Netgear WG311v3 Wireless Network Card on Ubuntu 11.04 amd64

    Problem

    The Netgear WG311v3 Wireless Network Card driver isn't automatically installed by Ubuntu 11.04.

    Solution

    1. Download and extract the custom driver from the following website.
    2. Open "Ubuntu Software Center" and install "ndiswrapper" (i.e. Windows Wireless Drivers)
    3. Open "Windows Wireless Drivers", and install the "WG311v3.INF" driver.
    4. Save and close.
    Give the system a couple of seconds, and it should recognise your wireless card. And thats it.

    See also:
    https://help.ubuntu.com/community/WifiDocs/Device/Netgear_WG311_v3