Saturday, August 16, 2008

Printing on a HP LaserJet over the network using Linux

The desktop given to me is connected to a printer HP Laserjet 2200 over network with an IP address. I wanted to configure it on Fedora. I already know about the fact that HP printers are well supported on Linux. This post might help you if are in similar kind of situation, that is, you want to connect to a network printer from a linux box over LAN. This post is only for the sake of convenience. If things don't work out and you need more information then you should visit this link.


Lets first see the system configuration.

$ uname -a
Linux localhost.localdomain 2.6.25.14-108.fc9.x86_64 #1 SMP Mon Aug 4 13:46:35 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux

So, basically I am using FC9 with x86_64 processor. This much is good enough for us.


Check if cups daemon is running. You can check at System->Administration->Services->Cups. It should be running. You can also check this on console using following command:

$ sudo /sbin/chkconfig --list|grep cups
cups 0:off 1:off 2:on 3:on 4:on 5:on 6:off

So, Cups is running on run-level 3, 4 and 5. If it is not running, then you should make it run first. Its not dificult and following command should do the job.

$ sudo /sbin/service cups start
or
$ sudo /sbin/chkconfig --level 345 cups on


Now, check if hplip is available on your system.

$ rpm -qa|grep hplip
hplip-2.8.2-2.fc9.x86_64
hplip-gui-2.8.2-2.fc9.x86_64

In case they are not present, use Yum to get the required packages:

$ sudo yum install hplip hplip-gui

If HPLIP is already installed then try running hp-setup to configure your printer.

$ sudo hp-setup



I choose the second option 'Network connection'. Then click on next.



It lists the printers available on the network. I choose the the HP LaserJet 2200 that is assigned to me and then click next.


It asks me to select a suitable PPD file available in the list. Usually you should select the one that closely matches the description of the printer. In this case I retain the first selection.


Here I add some description to my printer and click next. On the next screen it sends a test page for printer. It starts working !! I did not believe that the things would be this much simple. Because I remember spending days on getting my printer work on linux. I think those days are gone now. The life has certainly become more comfortable with linux.

Sunday, July 6, 2008

Remote Access on Linux

VNC server and vncviewers are quite popular for accessing linux desktops remotely either from a windows or a linux client. I won't discuss much about them as a lot of information is available on web about this. I would rather give links to some webpages here:


Rather than explaining things, I would just write down few commands to get you started. I am assuming you are using Debian Etch 4.0.

$ sudo apt-get install vncserver
$ vncserver :1 -geometry 1024x768 -depth 24 -pixelformat rgb565

It might ask you to enter a password to be used by users to connect your system through vnc.
The first time vncserver is started up, it will also create a configuration file, in your home directory, called $HOME/.vnc/xstartup. Execute the follow to stop vncserver.

$ vncserver -kill :1


On your client,

$ vncviewer :1


Best part is you can connect to a vncserver through an SSH tunnel using -via option with vncviewer. But install tightvncserver on the host machine. In order to use ssh tunnel, you need to provide username and password for ssh login. so the first password is for ssh login while the second password is for vncserver available in ~/.vnc/passwd. -Fullcolor option gives best display property for your vnc session.

[control@cube:]$ vncviewer -via swg@172.28.52.111 -Fullcolor insane:1

VNC Viewer Free Edition 4.1.1 for X - built Feb 26 2007 20:38:07
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.
swg@172.28.52.111's password: ***

Sun Apr 27 12:24:43 2008
CConn: connected to host localhost port 5599
CConnection: Server supports RFB protocol version 3.3
CConnection: Using RFB protocol version 3.3
Password: ***

Sun Apr 27 12:24:45 2008
TXImage: Using default colormap and visual, TrueColor, depth 24.
CConn: Using pixel format depth 24 (32bpp) little-endian rgb888
CConn: Using ZRLE encoding

Sun Apr 27 12:24:52 2008
CConn: Throughput 20000 kbit/s - changing to hextile encoding
CConn: Using hextile encoding


Connecting a Linux server from a windows client

There are two ways we can connect a linux machine from windows:

1. Using Putty to establish a ssh connection and exporting display using xmanager

2. Using VNC client to connect to vnc server running on linux machine.


I would describe both the methods as neatly as possible.

Putty+ Xmanager

1. Download "Xmanager" from this site.

http://www.netsarang.com/download/down_xme2.html

2. Install the Xmanager Enterprise 2.1 Build 0038 . In the serial
field type "evaluation".

3. Once installation is over, go to start -> all programs -> Xmanager
Enterprise -> xmanager-passive

4. Now run "putty.exe". Enter the IP of the ssh server you want to
connect. Click on connection -> ssh -> x11 on the left hand side bar
and on the right hand side click on "Enable X11 forwarding".


5. Now login to your ssh server and run any gui application.



VNC Server - client

1. Download realvnc viewer from this site. It would ask you to enter
user info. Don't enter anything and click on "proceed to download".

http://www.realvnc.com/products/free/4.1/winvncviewer.html

2. Download the following exe file and NOT the zipped one and put it on desktop.

VNC Free Edition Viewer for Windows
Stand-alone Viewer
Version 4.1.2

3. Double click on it. It would ask for Server. Enter following

your_vnc_server:1

4. Then it will ask for password only. Now enter the password provided to you.


5. Enter the password and you can the linux desktop.

Caution: First try to connect the vncserver from a linux desktop and make sure that it is working. Then only try from a windows machine.

Thursday, June 5, 2008

Renaming multiple files on Linux

The syntax for the rename command is:

rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

-v : verbose

-n : test run

perlexpr: perl regular expression

Example 1: change "*.htm" to "*.html"

$ rename -n ’s/\.htm$/\.html/’ *.htm

s - substitute : s/old/new

$ - end of string. That is search for only '.htm', not '.html'


Example 2: change filenames that have the pattern ########.JPG (8 numbers and capital .JPG) to something like BeachPics_########.jpg

$ rename -n 's/(\d{8})\.JPG$/BeachPics_$1\.jpg/' *.JPG

00001111.JPG renamed as BeachPics_00001111.jpg
00001112.JPG renamed as BeachPics_00001112.jpg
00001113.JPG renamed as BeachPics_00001113.jpg

\d{8} : count 8 digits

(\d{8}) : Parenthesis is meant to save this as an argument for later use

$1 : insert the string from the first set of parenthesis - in this case the 8 digits

$ rename -n 's/\d{5}(\d{3})\.JPG$/BeachPics_$1\.jpg/' *.JPG
00000123.JPG renamed as BeachPics_123.jpg
00000124.JPG renamed as BeachPics_124.jpg
00000125.JPG renamed as BeachPics_125.jpg

Example 3: replace 'weight_' to 'ffn_wt_' in all the files

$ rename -n 's/weight_*/ffn_wt_/g' *.txt
weight_far.txt renamed as ffn_wt_far.txt
weight_near.txt renamed as ffn_wt_near.txt
weight_top.txt renamed as ffn_wt_top.txt

Wednesday, May 28, 2008

Bash History

During last 5 years of using Linux, bash has been the application I used most. Yet, I know little about it. As I am writing more and more commands on the console, I am feeling a need for efficiency. This forced me to dig more into bash and its power! But as we all know, people have already done the hard work and kept things ready for us to make use of them.

In this article I would take about Bash history commands and how to efficiently use them. I won't do much apart from providing some good links in this regard:

  1. Deadman.org
  2. http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/

Summary of some commands:

  • Bash History
    • !! - repeat last command
    • !foo - repeat last command starting with 'foo'
    • CTRL + R - command auto completion
    • history - prints a numbered list of previously typed commands
    • !N - executes Nth command in the history list
    • !foo:p - prints a command without executing it
    • !$ - last argument (word) of the previous command
    • !* - all arguments of previous commands
    • ^error^correction - re-executes previous command by replacing 'error' with 'correction'
  • Home / END
    • CTRL + a - beginning of a line
    • CTRL + e - End of a line
    • CTRL + w - erase a word
    • CTRL + u - erase from here to the beginning of the line

  • Modifying History behaviour

    $ export HISTFILESIZE=500
    $ export HISTIGNORE="&:[ ]*:exit"
    This ignores repeated commands, commands that start with a space and 'exit' and they are not added to bash history

    $ shopt -s histappend
    $ shopt -s histverify
    allows users to verify a substituted history expansion.

    $ shopt -s histreedit
    allows users to re-edit a failed history substitution

    Put these lines into .bashrc file so that you won't have to type them again and again

Tuesday, March 11, 2008

Tryst with Xmgrace

Xmgrace is a great WYSIWYG 2D plotting software available with GNU/Linux. Unfortunately it does not support 3D plotting at the moment. If you want to produce good quality graphs for technical papers, you should try your hands at it.

Typesetting

Grace permits quite complex typesetting on a per string basis. Any string displayed (titles, legends, tick marks,...) may contain special control codes to display subscripts, change fonts within the string etc.


Example:

F\sX\N(\xe\f{}) = sin(\xe\f{})\#{b7}e\S-X\N\#{b7}cos(\xe\f{})

prints roughly

                       -x
F (e) = sin(e)·e ·cos(e)
x

using string's initial font and e prints as epsilon from the Symbol font.

NOTE: Characters from the upper half of the char table can be entered directly from the keyboard, using appropriate xmodmap(1) settings, or with the help of the font tool ("Window/Font tool").


Control code
Description
\f{x} switch to font named "x", e.g. \f{Times}
\f{n} switch to font number n
\f{} return to original font
\R{x} switch to color named "x"
\R{n} switch to color number n
\R{} return to original color
\#{x} treat "x" (must be of even length) as list of hexadecimal char codes
\t{xx xy yx yy} apply transformation matrix
\t{} reset transformation matrix
\z{x} zoom x times
\z{} return to original zoom
\r{x} rotate by x degrees
\l{x} slant by factor x
\v{x} shift vertically by x
\v{} return to unshifted baseline
\V{x} shift baseline by x
\V{} reset baseline
\h{x} horizontal shift by x
\n new line
\u begin underline
\U stop underline
\o begin overline
\O stop overline
\Fk enable kerning
\FK disable kerning
\Fl enable ligatures
\FL disable ligatures
\m{n} mark current position as n
\M{n} return to saved position n
\dl LtoR substring direction
\dr RtoL substring direction
\dL LtoR text advancing
\dR RtoL text advancing
\x switch to Symbol font (same as \f{Symbol})
\+ increase size (same as \z{1.19} ; 1.19 = sqrt(sqrt(2)))
\- decrease size (same as \z{0.84} ; 0.84 = 1/sqrt(sqrt(2)))
\s begin subscripting (same as \v{-0.4}\z{0.71})
\S begin superscripting (same as \v{0.6}\z{0.71})
\T{xx xy yx yy} same as \t{}\t{xx xy yx yy}
\Z{x} absolute zoom x times (same as \z{}\z{x})
\q make font oblique (same as \l{0.25})
\Q undo oblique (same as \l{-0.25})
\N return to normal style (same as \v{}\t{})
\\ print \
\n switch to font number n (0-9) (deprecated)
\c begin using upper 128 characters of set (deprecated)
\C stop using upper 128 characters of set (deprecated)

Putting Symbols into Axis labels:

If you need special characters or special formatting in your label, you can use grace escape sequences (the sequence will appear verbatim in the text field but will be rendered on the graph), see typesetting above. If you don't remember the mapping between alphabetic characters and the glyph you need in some specific fonts (mainly symbol and zapfdingbats), you can invoke the font tool from the text field by hitting CTRL-e. You can change fonts and select characters from there, they will be copied back in the text field when you press the "Accept" button. Beware of the position of the cursor as you enter text or change font in the font tool, the character or command will be inserted at this position, not at the end of the string!


Note that you should see \f{Symbol} in the Cstring field of font tool when you select a symbol. In case you don't, write down manually and then click on a symbol you wish to insert and then press 'Accept'.

overlaying graphs

  1. Begin by selecting Main:Edit/Overlay graphs to bring up the Overlay widget.
  2. Select the graph numbers with which we would like to deal. In this example, we will overlay graph 1 onto graph 0. At this point, only graph 0 is visible. We cannot see Graph 1 to select since it does not exist at this point. We need to create simply by pressing mouse button 3 in a graph list window and selecting create new.
  3. The overlay type is determined by what is common among the overlayed graphs. In our example, the x axis is common so we will select X-axes same, Y-axes different. This is important because we don't want to alter any axes of the Overlay graph which we set the same as the underlay graph. In this example, we don't want to alter the x-axis of graph 1.
  4. We are now ready to label the graph axes and read the data. One thing we must be careful to do is to always make sure that we are working on the intended graph. Seeing as the graphs are overlain, clicking within the frame is ambiguous as to what graph is selected. The rule is that in a region of overlay, clicking will cycle between the graphs. Hence, if graph 1 is selecting, clicking within the frame will toggle to graph 0.
  5. Making sure that graph 0 is active, bring up the Axis properties widget. Now set the y axis title to Gnus.
  6. Select graph 1 as active as set the title as Gnats. Notice how it overlaps the Gnus. We want to put this on the right side. From the axis label and bar tab, select label Properties/Side=Opposite.
  7. Label the x axis to label it. If graph 1 is the current graph, noticed how it is greyed out because only 1 x axis need be active. Select graph 0 and you should now be able to alter the axis label.
  8. You are ready to read in data. Just make sure the graph that is active when you read in the data (or create your set) is the one in which you intend it to go.

Saturday, March 8, 2008

Installing Matlab 7 on Fedora 7

I will just list common problems and their probable solutions.

Problem 1: The installer does not work.
http://www.mathworks.com/support/solutions/data/1-12E9FJ.html?solution=1-12E9FJ

libXp.so.6: cannot open shared object file: No such file or directory

You need to install "libXp-devel" package.

# yum install libXp-devel

Problem 2:
Why does MATLAB fail to launch on Linux machines with an error about Assertion `c->xlib.lock' failed

http://www.mathworks.com/support/solutions/data/1-54UIFE.html?solution=1-54UIFE



Problem 3: When launching matlab, you may get following error

error while loading shared libraries: /usr/local/matlab73/bin/glnx86/libmwlapack.so: cannot restore segment prot after reloc: Permission denied

There are two solutions - first, you disable SELINUX. The other solution is to allow the permission in SELinux administration itself.

Open the SELinux Administration GUI and set the following Memory Protection Boolean to true.

Allow all unconfirmed executables to use libraries
requiring text relocation that are not labeled texttrel_shlib_t
.

or run following command on console

# chcon -t texrel_shlib_t /usr/local/matlab2006b/bin/glnx86/*.so