Archive for the “UNIX” Category

Embedded Fonts in Pdf

 

It is often that we need to submit paper or report electronically in portable document format (p.d.f.) that requires the fonts are embedded so that it is easily distributed or printed in various machines and p.d.f. version. It is usual for us to encounter the problem of emmbeded fonts simply because we use our own p.d.f converter. It may be from the pdf driver such as cutepdf, primopdf or our ghost script p.d.f converter.

Here is some "hacking techniques" to debug the problem of embedded fonts (in linux, taken from [1]).  Suppose your non-working p.d.f file is text.pdf

 

(1) convert to ps (postscript file):
pdftops text.pdf

(2) convert back to pdf using prepress settings:
ps2pdf14 -dPDFSETTINGS=/prepress text.ps

(3) check new text.pdf for horrendous formatting errors due to double conversion, and embedded fonts as above.

 

http://axiom.anu.edu.au/~luke/embedded_fonts.html

 

Sep 2, 2009 Posted Under: HOW TO, Portable Document, UNIX   Read More

Back-up File with Rsync

 

Description

Rsync is a command in unix/linux terminal that enables us to transfer just the differences between two folders interconected to some networks. The italic word just gives us a clue on how to transfer files efficiently. One application of this usability is for speeding up back-up processes, i.e. no need for transfer a big chunk of folder that we have in both ends but only the differences between them.

How does it work?

We can straightly use it from the linux terminal. Ex: in ubuntu open applications -> accessories –> terminal 

 

Local machine:  rsync [OPTION...] SRC... [DEST]

Access via remote shell:
  Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
  Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

Access via rsync daemon:
  Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
        rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
  Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
        rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

For Frequent Back-up

For frequent back-up, it will be convenient if we can make a shell command file containing the necessary instructions for back up. With just calling that command, the back-up will be done in few seconds/minutes (depending on the folder size). Here is an example (case study).

Remote server for backup: www.backupdomain.com, folder: $HOME/test, username: user

Local folder: $HOME/Documents/test

We can create the shell command file as follows.

#!/bin/bash
STRING:"Backup is done"
rsync -avz –delete -e ssh ~/Documents/test  use@backupdomain.com:~/test
echo $STRING
exit 0

save the above shell command in executable .sh file and just invoke the command whenever it is necessary. We may want to put the command in the cron-job for scheduled backup..

Note that the option –delete means that the backup will delete the file that does not exist at the sender side.

 

Reference: 

[1] http://www.samba.org/ftp/rsync/rsync.html

Jul 19, 2009 Posted Under: HOW TO, UNIX   Read More

How To: Handle compressed (tar.gz) file using tar

Syntax

tar -[option] [compressed file]

For reference purposes, the following list is a description of the tar options used to extract compressed file :

x (extract)
tar will extract from the passed filename (as opposed to creating a new file).

v (verbose)
tar will print verbose output as files are extracted. You may omit this flag if you do not wish to see each file as it is unpacked.

z (zipped)
tar will use gunzip to decompress the source. This option assumes that you are using the GNU tools; other versions of tar may not support the z flag. In the event that you are not using the GNU tools, you will need to manually unzip the file using gunzip before you can unpack it with tar.

f (file)
tar will use the filename following the f parameter to determine which file to extract.

 

Jul 6, 2009 Posted Under: HOW TO, UNIX   Read More

How To: Checking version of installed MySQL Server

In order to check the version of installed MySQL Server, we can use following command

mysql -V

The result in our machine is

mysql version 14.12 Distrib 5.0.26, for pc-linux-gnu (86_64) using readline 5.0

 

Jul 5, 2009 Posted Under: HOW TO, UNIX   Read More

How To: SSH Tunneling to connect local pgAdmin to remote PostgreSQL

 

Case: There is a need to use pgAdmin in local machine to connect to the postgresql remotely. One option is use SSH tunneling from local machine to remote machine.

Assumption made:

in remote machine, the postgresql run in port 5432 (default port)

SSH can be use to encrypt the network connection between clients and a PostgreSQL server. First make sure that an SSH server is running properly on the same machine as the PostgreSQL server and that you can log in using ssh as some user.

To create tunnel between our machine and remote machine using SSH, we could use command:

ssh -L [local port]:[localhost]:[remote port] [user]@[remote machine domain]

example:

ssh -L 5454:localhost:5432 user007@some-domain.com

you will be prompted to enter the password of the user007 in the some-domain.com

Open the pgAdmin and add new server. Set host to localhost, port 5454, SSL is not required, set maintained DB to blank.

Jul 5, 2009 Posted Under: HOW TO, UNIX   Read More

Installing multiple tomcat instances on the Apache 2 webserver

 

This article will explain how to install tomcat webserver as a extension of Apache 2 webserver. Apache webserver will act as a proxy for n tomcat instances installed in the machine. This articles is written based on the need of installing multiple instances of tomcat webserver in the one physical server. We assume there are existing Apache 2 webserver already installed in the machine, JVM has been installed as well. We also assume that we have registered domain softonelogic.com and our aim is installing tomcat for main softonelogic.com and sub domain funds.softonelogic.com.

The steps required for tomcat installation will be divided into 2 section, setting in Apache 2 side and setting in the tomcat side

Apache 2 setting

Register new domain name in to Apache 2

Register domain to the DNS system in the machine. In our lab, we are using tinydns to handle DNS in our machine. The command to add new domain in the apache are:

# cd /service/tinydns/root
# ./add-ns new-domain.org 192.168.0.2
# make

Replace new-domain.org with the desired domain. In our case will be funds.softonelogic.com. And change the 192.168.0.2 to the correct IP Address.

The /var/tinydns/root/data file is where all your DNS entries are stored. There are a number of scripts inside /var/tinydns/root that will help you add various lines to your data file. Whenever you edit the data file,  run ’make’ in the root dir to "compile" the data file into a tinydns readable file.

You can use the scripts to add nameservers, aliases, childns servers, mx servers, and regular hosts. After using the scripts, and seeing what they do, you might be comfortable enough to edit the data file directly. Hence, to make it easy, adding a new domain quickly, just add these 4 lines to the end of the file:1

.new-domain.org:203.211.130.159:a:259200
.new-domain.org:203.211.130.158:b:259200
@new-domain.org:203.211.130.159:a::86400
+new-domain.org:203.211.130.159:86400

Virtual Host

To add a new virtual host, create a file with .conf extension in the /etc/apache2/vhosts.d/ you can copy one of the conf file in it to get started with, and then edit the file. The conf file is self explanatory. Please refer to Apache Virtual Host Documentation8 for more details. If you specify the ErrorLog in the conf file, make sure you create an empty file for the log.

Once you have finished editing the conf file, restart the apache.

Edit /etc/apache2/workers.properties.

This file contains the details about how each process is linked to Tomcat by defining workers that communicate through the ajpv13 protocol. Refer to the Workers HowTo
for more detail.

(a) Add more worker entry in the worker.list. This variable is comma separated without containing any space. Tip: You can add it right away after the equal sign (=) since the order doesn’t matter.

worker.list=ajpnewapp,ajpexistingapp

(b) Add at least the type, host and port properties of the worker somewhere after the worker.list. The combination of host and port values between applications must not be the same. The easiest way is to use different host (or ip) and use the same port.

worker.ajpnewapp .type=ajp13
worker.ajpnewapp .host=127.0.0.n*
worker.ajpnewapp .port=8009

* Where n is a number between 1 to 254. Your system has been pre-set to all these IPs.

Create the apache vhost configuration file in the /etc/apache2/vhosts.d/

The difference with the regular apache vhost is that you need to specify the mount point. This is where JkMount parameter comes in.

JkMount /a_folder* ajpnewapp

Restart the apache.

Tomcat Setting

Unzip compressed tomcat folder in the path /opt/

rename the unzipped file to any name that easy to remember, example apache-tomcat-softonelogic-portal

mv apache-tomcat-6.0.20 apache-tomcat-softonelogic-portal

Since the tomcat will be run by non-root user, we need to change the ownership of the tomcat.

syntax: chown -[option] [user].[group] target-folder-ownership-to-be-changed

Assume we have user called softonelogic and group tomcat, so the command will be

chown -R softonelogic.tomcat apache-tomcat-softonelogic-portal

-R recursively

Then create symbolic link the apache-tomcat-softonelogic-portal at the /home directory or any other directory you want. This article, the symbolic link will be placed at /home/softonelogic

login as user softonelogic

ln -s /opt/apache-tomcat-softonelogic-portal ./tomcat

to test the symbolic link

ls -l

You should see tomcat->/opt/apache-tomcat-softonelogic-portal

Next, go to tomcat directory at /opt/ go to directory conf, edit the server.xml

vi server.xml

Fine <Connector by using command

/Connector

in command mode of vi

Find the Connector that define the AJP 1.3 connector. Compare the address and port with the worker.properties

Next, run the tomcat. Go to the bin folder in the tomcat, run

./startup.sh

You should get the tomcat homepage or any other defined page.

Jul 5, 2009 Posted Under: Java Enterprise Edition, UNIX   Read More

How To: vi Text Editor

 

A text editor is a program used to create and modify the text files. Two principal Unix text editor are vi and emacs. Powerful, mature, full-featured program, by far, the most widely used editors.

Starting vi

To start vi, the basic syntax is:

vi [-rR] [file]

Command mode and input mode

When working with vi, data is kept in a storage called an editing buffer. If we can to edit file using vi, vi copies the contents of the file to the editing buffer. We are not working with the original, we use the copy instead.

Command Mode

Whichever typed keys will be interpreted as commands.

Input Mode

Everything key typed to the editor, will be inserted directly into a buffer.

Inserting Text

There are tweleve commands to change to input mode. Half of these commands are for entering new data; the other half are for replacing existing text.

Here are the commands:

Command     
Description
i change to input mode: insert before cursor position
a change to input mode: insert after curson position
I change to input mode: insert at start of current line
A change to input mode; insert at end of the current link
o change to input mode: open bellow current line
O change to input mode; open above current line

 

Deleting Text

There are several ways to delete data from the editing buffer, using both vi and ex commands. The vi commands are:

Command Description
x delete character at cursor
X delete character to left of cursor
D delete from cursor to end of line
dmove delete fro cursor to move
dd delete the entire current line

 

 Writting Data to a File

There are several command to write data to a file. The commands are:

Command Description
:w write data to original file
:w file

write data to a new file

:w! file overwrite an existing file
:w>> file append data to specified file

Find sometext

/sometext

Jul 2, 2009 Posted Under: HOW TO, UNIX   Read More