Archive for the ‘linux’ Category

debian: บันทึก imagemagick - convert

แปลงรูปจาก jpg ธรรมดา ไปเป็น jpg แบบ interlace
ใช้คำสั่งคือ
# mkdir temp
# for i in *jpg; do convert $i -interlace line temp/$i ; done

จะได้ไฟล์ jpg ชุดใหม่เข้าไปอยู่ในไดเรกทอรี่ temp
แปลงหลายรูป จาก tif ไปเป็น pdf
# convert -adjoin `ls *.tif` newfile.pdf
เอามาจาก jmetrix : Viewing multiple page tif on Linux
แปลง tif หลายไฟล์ไปเป็น tif ไฟล์เดียวหลายภาพ
$ convert x1.tif x2.tif x3.tif -adjoin newfile.tif
แตก tif แบบหลายภาพ ออกมาเป็นหลายไฟล์ ไฟล์ละหนึ่งหน้า
$ convert x.tif x%d.tif
จะได้ออกมาเป็น x1.tif x2.tif x3.tif
เอามาจาก [magick-users] how to split multi-page tiff into single pages

หมายเหตุ
ต้องลงแพกเกจ imagemagick ก่อน
# aptitude install imagemagick

imagemagick: การแก้ไข multiple pages tif

ยังหาโปรแกรมที่ใช้แก้ไขภาพ tif แบบหลายหน้า แบบ Imaging for Windows บนลินุกซ์ไม่ได้
ก็คงต้องใช้แบบบรรทัดคำสั่งไปพลาง ๆ ก่อน

ขั้นตอนคือ
ต้องลง ImageMagick ก่อน
$ sudo aptitude install imagemagick

แตกไฟล์ tif แบบหลายหน้าออกมาเป็น แบบหน้าเดียวหลายไฟล์
$ convert image.tif x%d.tif

แก้ไขหน้าที่ต้องการจากไฟล์ที่แตกออกมาแล้ว ด้วย gimp สมมุติว่าเป็นหน้า 2
$ gimp x2.tif

เมื่อบันทึกเรียบร้อยแล้ว ก็รวมกลับเป็นไฟล์เดียวตามเดิม สมมุติว่ามีทั้งหมด 3 ไฟล์
$ convert x1.tif x2.tif x3.tif -adjoin newimage.tif

ถ้าจะให้บีบอัดด้วย

  • ถ้าเป็นภาพสีหรือสีเทา
    $ convert newimage.tif -compress lzw newimage.tif
  • ถ้าเป็นภาพแบบขาวดำ
    $ convert newimage.tif -compress fax newimage.tif
  • สำหรับการบีบอัดมีพารามิเตอร์คือ None BZip Fax Group4 JPEG JPEG2000 Lossless LZW RLE และ Zip
    ต้องทดลองเลือกใช้ดูให้เหมาะกับประเภทของภาพ

ลยไฟล์ย่อยทิ้ง
$ rm x?.tif

ดูผลได้ด้วย evince
$ evince newimage.tif

อ้างอิง : debian: บันทึก imagemagick - convert

*** โปรดระวัง - ไม่สามารถใช้กับไฟล์ tif ที่มีข้อมูล annotation ได้ ***

update
จากขั้นตอนข้างบน สามารถนำมาเขียนสคริปต์ทำให้ใช้คำสั่งเดียวได้ ดังนี้
สมมุติว่าจะต้องการแก้ไข image.tif ในหน้า 0 และหน้า 1 สั่งจากสคริปต์ว่า
$ d.edittif image.tif 0 1
gimp จะเปิดไฟล์ออกมา 2 ไฟล์ คือหน้าแรก และหน้าที่สอง
หลังจากบันทึกและปิด gimp แล้ว จะได้ไฟล์ image-new.tif ออกมาเป็นภาพที่แก้ไขแล้วพร้อมบีบอัดเรียบร้อย

เนื้อไฟล์ d.edittif มีดังนี้
$ sudo touch /usr/local/bin/d.edittif
$ sudo chmod 755 /usr/local/bin/d.edittif
$ sudo vi /usr/local/bin/d.edittif

#!/bin/bash
# EDIT MULTIPLE PAGES TIF FILE
# PREREQUIST: gimp imagemagick evince

#NAME=${0##*/}
NAME=`basename $0`

USAGE=" Usage: $NAME FILE PAGE0 PAGE1 ...
    ex1: $NAME image.tif 0 1 = Edit file image.tif on PAGE0 and PAGE1"

phelp()
{
    echo "$NAME: edit multiple pages tif.
$USAGE"
}

while getopts "h" opt; do
    case "$opt" in
    h)  phelp; exit 0;;
    *)  echo "$Usage" 1>&2; exit 2;;
    esac
done

shift $((OPTIND - 1))

if [ ! $2 ]; then
    phelp
    exit 1;
fi

TIF=$1
shift

FILE=${TIF%.*}      #STRIP FILENAME

EDITFILE=”"
while [ $1 ]; do
    EDITFILE=”$EDITFILE ~${FILE}$1.tif”
    shift
done

ALLFILE=`ls ~${FILE}*.tif`

if [ -f $TIF ]; then
    echo “Process $TIF”
    /usr/bin/convert $TIF “~$FILE%d.tif”
    if [ -f "~${FILE}0.tif" ]; then
        #EDIT WITH gimp
        echo “Edit $EDITFILE”
        /usr/bin/gimp $EDITFILE

        #COMPRESS EACH TIF
        for i in $ALLFILE; do
            echo -n “IDENTIFY $i ”
            if /usr/bin/identify -verbose $i | grep “Gray: 1-bits”; then
                /usr/bin/convert $i -compress fax $i
            else
                /usr/bin/convert $i -compress lzw $i
            fi
        done

        /usr/bin/convert $ALLFILE -adjoin -compress lzw “$FILE-new.tif” #COMPRESS & JOIN
        /usr/bin/evince “$FILE-new.tif”     #VIEW NEW FILE
        rm $ALLFILE     #DELETE ALL SPLIT FILE
    fi
fi

ลองบนเดเบียน sid ครับ

imagemagick: ทำ annotate ไฟล์ tif

ความจำเป็นบีบบังคับให้ต้องรีบหาโปรแกรมที่สามารถทำ Annotation ไฟล์ tif ให้ได้
จริง ๆ ก็มีโปรแกรมชื่อ Xournal ที่สามารถทำ annotate บน pdf ได้
ซึ่งเราอาจแปลง tif ไปเป็น pdf ก่อน แล้วจึงค่อยลงมือแก้ไข
แต่พบว่าในรุ่นปัจจุบันบน sid คือ 0.3.3 ยังทำ Text annotation ไม่ได้
และรุ่นล่าสุด 0.4 ความสามารถและการใช้งานยังค่อนข้างด้อยกว่าที่ Kodakimg ทำได้อยู่โข

แต่จากครั้งก่อนที่ทำ การแก้ไข multiple pages tif
คราวนี้เลยได้ความคิดว่าถ้าลองเปลี่ยนจาก Gimp มาเป็น Inkscape เราก็จะได้ความสามารถในการทำ annotation จาก inkscape ในแบบที่ก้าวหน้าสุด ๆ

มีปัญหาที่ต้องแก้คือ inkscape ไม่สามารถแก้ไขไฟล์แบบหลายหน้าได้ (แต่ในอนาคตคงมาแน่ ๆ เห็นอยู่ใน wishlist ลำดับต้น ๆ )
ทางแก้แบบชั่วคราวคือ กระจายไฟล์ลงในไดเรคทอรี่ชั่วคราวที่สร้างไว้ แล้วแก้ไขตามไฟล์ที่เราระบุ

อีกปัญหาคือเวลาแปลงกลับจาก svg มาเป็น tif แบบหลายหน้าแล้ว ข้อมูล annotation ที่เราทำไว้ จะถูกแปลงเป็นข้อมูล bitmap ฝังรวมกับไฟล์ tif ไปหมด
ทางแก้ชั่วคราวอีกเหมือนกันคือ ให้คงไดเรกทอรี่ชั่วคราวนี้ไว้ โดยไม่ลบไฟล์ทิ้งเลย เมื่อเวลาเราใช้คำสั่ง annotate ครั้งใหม่ เขาก็จะมาแก้ไขต่อจากที่เราเคยแก้เอาไว้ โดยต้องยอมรกรุงรังบ้าง

เนื้อแบตช์ไฟล์มีดังนี้
$ sudo vi /usr/local/bin/d.tifannotate

#!/bin/bash
# ANNOTATE MULTIPLE PAGES TIF FILE
# PREREQUIST: inkscape imagemagick evince

#NAME=${0##*/}
NAME=`basename $0`

USAGE=" Usage: $NAME FILE PAGE0 PAGE1 ...
    ex1: $NAME image.tif 0 1 = Edit file image.tif on PAGE0 and PAGE1"

phelp()
{
    echo "$NAME: annotate multiple pages tif.
$USAGE"
}

while getopts "h" opt; do
    case "$opt" in
    h)  phelp; exit 0;;
    *)  echo "$Usage" 1>&2; exit 2;;
    esac
done

shift $((OPTIND - 1))

if [ ! $2 ]; then
    phelp
    exit 1;
fi

TIF=$1
shift

FILE=${TIF%.*}      #STRIP FILENAME
TEMPDIR=”${FILE}~”

EDITFILES=”"
while [ $1 ]; do
    EDITFILES=”$EDITFILES ${FILE}$1.svg”
    shift
done

INKSCAPE=`which inkscape`
IDENTIFY=`which identify`
CONVERT=`which convert`
VIEW=`which evince`
if [ -f $TIF ]; then
    echo “Process $TIF”
    #TEST TEMP DIR EXIST
    if ! [ -d $TEMPDIR ]; then
        #CREATE TEMP DIR AND SPLIT tif INTO
        mkdir $TEMPDIR
        $CONVERT $TIF “${TEMPDIR}/$FILE%d.tif”

        #ENTER WORKING TEMP DIR
        pushd $TEMPDIR

        ALLFILE=`ls ${FILE}*.tif`
        #CONVERT TO svg
        for i in $ALLFILE; do
            $INKSCAPE -l “${i%.*}.svg” $i
        done
    else
        #ELSE; EDIT OLD svg
        pushd $TEMPDIR
    fi

    #ANNOTATE
    if [ -f "${FILE}0.svg" ]; then
        #ANNOTATE WITH inkscape
        echo “Edit $EDITFILES”
        $INKSCAPE $EDITFILES

        ALLSVG=`ls ${FILE}*.svg`
        #CONVERT ADJOIN
        $CONVERT $ALLSVG -adjoin -compress lzw “$FILE-new.tif”  #COMPRESS & JOIN
        $VIEW “$FILE-new.tif”       #VIEW NEW FILE
        mv “$FILE-new.tif” ..
    fi

    #EXIT WORK DIR
    popd

    #REMOVE DIR
    #rm -rf $TEMPDIR
fi

$ sudo chmod 755 /usr/local/bin/d.tifannotate

เรียกใช้งานด้วยคำสั่ง… โปรแกรม ไฟล์tif หน้าที่ต้องการแก้ไข
$ d.tifannotate FILE.tif 0 1 ...
จะได้ไฟล์ที่ทำ annotate แล้วชื่อ FILE-new.tif และไดเรกทอรี่ชั่วคราวชื่อ FILE~ เหลืออยู่ เพื่อใช้ในการแก้ไขครั้งต่อไป (แต่ถ้าไม่ได้ใช้แน่ ๆ ก็อาจเติมคำสั่งลบต่อท้ายแบตช์ไฟล์ หรือลบด้วยมือเอาทีหลังก็ได้ครับ)

กระท่อนกระแท่นหน่อย เพราะเป็นการทำเพื่อรอโปรแกรมลินุกซ์แนวนี้ในอนาคตตัวจริง ก็พอใช้งานได้ไปพลาง ๆ ก่อนครับ

อย่าลืม เปลี่ยนขนาดกระดาษไน inkscape ด้วย

แต่ติดใจการใช้งาน annotation บน inkscape จริง ๆ แฮะ

  • Comments Off

install odbc on debain

For those of you that may not know what unixodbc does, “ODBC is an open specification for providing application developers with a predictable API with which to access Data Sources. Data Sources include SQL Servers and any Data Source with an ODBC Driver.” They include a text file driver as an example of a non-SQL source. Two examples are Asterisk and OpenOffice.org.

Unixodbc allows cross-platform use of databases with many bridges available in many popular programming languages.

Installing and configuring isn’t necessarily as simple as “apt-get install unixodbc“. This HOWTO was written on Etch and may vary if you are using a different version.

Step 1: Download Packages

Running:

apt-get install unixodbc libmyodbc odbc-postgresql \
   odbcinst1debian1

will get you the ODBC binaries, database drivers for MySQL and PostgreSQL and a Debian helper application for ODBC respectively.

Step 2: Add odbcinst.ini Records

As the root user, check for two empty text files /etc/odbc.ini and /etc/odbcinst.ini. If they aren’t there, then create them. (eg. “touch /etc/odbcinst.ini“)

Create a directory for the odbcinst.ini scripts:

username@host:~$ mkdir  /home/username/odbc

Step 3: Adding ODBC Instances

In order to minimize entry-error, I use text files to load ODBC instances. Odbcinst’s error messages are a bit cryptic so I control errors using a separate file for each database type.

As root create a file name pgsql and paste the following into it.

[PostgreSQL]
Description     = PostgreSQL driver for Linux & Win32
Driver          = /usr/lib/odbc/psqlodbca.so
Setup           = /usr/lib/odbc/libodbcpsqlS.so
FileUsage       = 1

If you are on another version double-check your library names.

Name the file pgsql so the following command should work.

odbcinst -i -d -f /home/username/odbc/pgsql

You can create another file for MySQL with the following contents:

[MySQL]
Description     = MySQL driver for Linux & Win32
Driver          = /usr/lib/odbc/libmyodbc3_r-3.51.11.so
Setup           = /usr/lib/odbc/libodbcmyS.so
FileUsage       = 1

To use it run, as root: “odbcinst -i -d -f /home/username/odbc/mysql“.

With PostgreSQL and MySQL done, lets create a sample ODBC connection!

Step 4: Create ODBC Connection

Create another text file and copy the text below into it. I called it asterisk. Copy the contents of this file into odbc.ini. (Note, in theory “odbcinst -i -s -f /path/to/file” writes the contents of the named file into /etc/odbc.ini. I could not get it to do so and there were no error messages) So, copy and paste the following into odbc.ini too

[asterisk]
Description = MySQL Asterisk
Driver      = MySQL
SERVER      = localhost
USER        = username
PASSWORD    = password
PORT        = 3306
DATABASE    = asterisk
Option      = 3

Make sure your database permissions are configured to allow the login/connection before testing.

Step 5 Test Connection:

As the root enter run:

 isql asterisk

This should put you into the asterisk database!

  • Comments Off

postgres install on debian

apt-get update
apt-get install pgsql

Create Language

Example plpgsql

su postgres
createlang plpgsql template1
exit

Change authentication method

We need to edit file pg_hba.conf to change authentification method for accessing PostgreSQL database.

cp /etc/postgresql/pg_hba.conf /etc/postgresql/pg_hba.confbak
vi  /etc/postgresql/pg_hba.conf

Find this section

# TYPE  DATABASE  USER  IP-ADDRESS  IP-MASK  METHOD
# Database administrative login by UNIX sockets
local  all  postgres        ident sameuser
#
# All other connections by UNIX sockets
local  all  all        ident sameuser
#
# All IPv4 connections from localhost
host  all  all  127.0.0.1  255.255.255.255  ident sameuser
#
# All IPv6 localhost connections
host  all  all  ::1  ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff  ident sameuser
host  all  all    ::ffff:127.0.0.1/128  ident sameuser
#
# reject all other connection attempts
host  all  all  0.0.0.0  0.0.0.0  reject

Edit that section to

# TYPE  DATABASE  USER  IP-ADDRESS  IP-MASK  METHOD
# Database administrative login by UNIX sockets
local  all  postgres        ident sameuser
#
# All other connections by UNIX sockets
local  all  all        password
#
# All IPv4 connections from localhost
host  all  all  127.0.0.1  255.255.255.255  password
#
# All IPv6 localhost connections
host  all  all  ::1  ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff  password
host  all  all    ::ffff:127.0.0.1/128  password
#
# reject all other connection attempts
host  all  all  0.0.0.0  0.0.0.0  reject

Restart PostgreSQL Server

/etc/init.d/postgresql restart

Create a New Database

Example wordpress

su postgres
createdb -T template1 wordpress
exit

Create a New User

Example: User supriyadisw with password cak3p

su postgres
createuser supriyadisw -P
Enter password for new user: cak3p [enter]
Enter it again: cak3p [enter]
Shall the new user be allowed to create databases? (y/n) y [enter]
Shall the new user be allowed to create more new users? (y/n) n [enter]
CREATE USER
exit

Login to PostgreSQL

pgsql -U supriyadisw wordpress [enter]
Password: cak3p [enter]

Good Luck :D

  • Comments Off

lspci command notfound

aptitude install pciutils

  • Comments Off

This brief introduction for configuring sites and modules in Debian’s Apache 2 package explains how to add and remove sites using the supplied tools, along with adding and removing modules.

The main source of confusiong comes from the various directories stored beneath /etc/apache2:

sites-available
A list of configuration files - one per site. A blank install will contain the file default. The system admin can have as many sites here as they need - however - they will not all be active.
sites-enabled
A list of symlinks to configuration files in sites-available. A blank install will contain a symlink 000default to sites-available/default. The sites listed here are the sites which will be active. The site to be used if no virtual hosts match will be the first file found (hence the 000 on 000default).
mods-available
A list of configuration files - one or more per module. Each dpkg installed module will add files here. e.g. php4.conf and php4.load are added with the libapache2-mod-php package. Again - the system admin can install whatever modules they wish - however - until they are set available they will not be active.
mods-enabled
A list of symlinks to configuratioon files in modes-available. Only modules linked in here will be activated on the webserver.

Now - several discussions on #debian IRC channel on freenode recently have had people advising others to either copy files from the available to the enabled directories or to manually symlink them. The user has, however, a better option - the four commands a2ensite, a2dissite, a2enmod and a2dismod

a2ensite
Will create the correct symlinks in sites-enabled to allow the site configured in sitefilename to be served
a2dissite
Will remove the symlinks from sites-enabled so that the site configured in sitefilename will not be served
a2enmod
e.g. a2enmod php4 will create the correct symlinks in mods-enabled to allow the module to be used. In this example it will link both php4.conf and php4.load for the user
a2dismod
Will remove the symlinks from mods-enabled so that the module cannot be used

We covered these this new layout briefly when discussing the upgrade from Apache 1.x to 2.x, and again when dicussing how to enable mod_rewrite for Apache.

  • Comments Off

Configuring OpenSSH to accept public-key authentication

To enable your OpenSSH to accept version 2 public key, you would need to modify /etc/ssh/sshd_config. You could use vi editor (or whatever editor you are familiar with) to uncomment/add/modify the following lines to /etc/ssh/sshd_config:

# the default SSH port is 22, you could alter it if necessary
Port 22

# accept version 2 keys only
Protocol 2

# NEVER allow root to login directly over the net
PermitRootLogin no
StrictModes yes
MaxAuthTries 3

# enable public-key authentication
RSAAuthentication no
PubkeyAuthentication yes

# securing your OpenSSH
# do not use host-based authentication for security reason
RhostsRSAAuthentication no
HostbasedAuthentication no
IgnoreUserKnownHosts yes
PermitEmptyPassword no

# do not allow telnet-type login for security reason
ChallengeResponseAuthentication no
PasswordAuthentication no

X11Forwarding yes
X11DisplayOffset 10

After you have made changes to /etc/ssh/sshd_config, you would need to restart the OpenSSH daemon by executing `/etc/init.d/ssh restart` (on Ubuntu).

Generating OpenSSH private and public key pair

To use public key authentication, the first step is to generate a pair of private and public keys on the Linux side. I would assume that you login as a user called “toylet”.

1. Login Linux as user "toylet". You could do it at the Linux console
   or via telnet.
2. Execute `ssh-keygen -t rsa` to generate a version 2 public
   and private key pair into directory /home/user/.ssh.
   The passphrase is optional (but preferred).

toylet@server:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/toylet/.ssh/id_rsa):
/home/toylet/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/toylet/.ssh/id_rsa.
Your public key has been saved in /home/toylet/.ssh/id_rsa.pub.
The key fingerprint is:
ec:f4:3f:b5:fe:2f:de:22:6c:42:8c:38:ad:6c:5e:96 toylet@server

3. Execute `cd /home/toylet/.ssh`
4. You should see 2 files: id_rsa and id_rsa.pub.
   Now execute the following command:
   cp id_rsa.pub authorized_keys
5. Copy /home/toylet/.ssh/id_rsa from Linux to Windows.

Converting the OpenSSH private key to Putty format

Next, we head to the Windows side. In step 4, you created two key files (id_rsa and id_rsa.pub). Putty cannot directly open OpenSSH keys. We need to convert id_rsa to id_rsa.ppk using a program called puttygen.exe.

6. At the Windows side, download puttygen.exe from Putty website.
7. Execute puttygen.exe

8. Click File->Load Private Key, load the file "id_rsa" from Step 5.
   Enter the passphrase if you used it in step 2.

9. Now the key has been loaded as in the figure above.
   Hit the button "Save private key".
   The converted key would be saved as "id_rsa.ppk".

Logging in Openssh using id_rsa.ppk

Download putty.exe from Putty website. It’s time to really login OpenSSH using putty.exe on Windows side. The steps here would be a little bit more complicated.

10. Invoke putty.exe
10.1. Click "Session" in the sidebar.

10.1.1. Enter ip address of your server (e.g., 192.168.1.2)
10.1.2. Click "SSH" in the Protocol option
10.2. Choose "SSH" under "Connection" in the sidebar

10.2.1. In "Preferred SSH protocol version", select "2 only"
10.2.2. click "Auth" under "SSH"

10.2.2.1. Hit the Browse button, select the file "id_rsa.ppk" from Step 9.
10.3. hit "Session" again in step 10.1

10.3.1. Enter a name (e.g. "toylet.session") in the textbox directly
        under "Saved Sessions".
10.3.2. Hit the "Save" button. The name "toylet.session" would appear in
        the listbox of "Saved Sessions".

10.4. Double-click "toylet.session". Now you would be presented
      with a login screen for OpenSSH.
10.4.1. Enter the linux user name "toylet"
10.4.2. Enter the passphrase if you specified it in step 2.

Login as: toylet
Authenticating with public key "imported-openssh-key"
Passphrase for key "imported-openssh-key":
Last login: Wed May 31 12:35:00 2006 from 192.168.1.10
toylet@server:~$

11. You have successfully logged into your Linux server via OpenSSH.
  • Comments Off

Time

Mp3

Msn status

  • manon2029@hotmail.com is

Chat with Meeh

Donate

    If you find an article useful, then please make a donation.

หมวดหมู่

UserOnline

Counter

  • Visitors today: 186
  • Visitors yesterday: 535
  • Visitors per day: 609
  • Max. visitors per day: 665
  • Total page views: 749,950
  • Page views of this page: 609
  • Currently online: 9
  • Max. online: 192
  • Total visitors: 157,603
  • counterStatistics