dimarts, 23 de desembre del 2008

Reinstal·lar un paquet Debian

Si hem desinstal·lat un paquet Debian (a Ubuntu hem fet apt-get remove "paquet") i, al instal·lar-lo de nou ens dona errors, podem intentar fer el següent:

Per exemple, si fos la paquet postfix:

apt-get install --reinstall postfix

dimarts, 16 de desembre del 2008

Serveis escoltant peticions de xarxa

Per conèixer els serveis que tenim escoltant peticions de xarxa podem executar:

netstat -tap

Si volem buscar algun servei en concret poden executar, per exemple:

netstat -tap | grep pop3

divendres, 5 de setembre del 2008

PHP5: session_start() i session_write_close()

Al posar en funcionament un servidor LAMP, ens serà prou fàcil i trobarem molta informació sobre multitasking, tant a l'Apache com al MySQL com per al PHP.

Jo em vaig trobar amb un cas curiós. Tot i haver configurat tot assegurant les capacitats de multitasca, al treballar desde un mateix client web i amb una mateixa sessió el multitasquing no funcionava. Fins que no es carregava una pàgina no s'iniciava la càrrega de la següent.

Després de molt buscar vaig trovar (al manual oficial del PHP, que ja te gràcia la cosa) que al iniciar un script php i cridar la funció session_start() el php bloqueja la crida de aquesta funció des de altres scripts per a la mateixa sessió. El motiu es prou raonable, doncs els valors de la sessió son per passar-los d'un script a l'altre, i si en un script els estem modificant podriem generar inconsistències als altres scripts.

Per sort, vaig descobrir que la funció session_write_close() bloqueja les variables de la sessió per a escriptura, però permet treballar amb tota normalitat amb la seva funcionalitat. Així doncs, per a cada script cal començar amb la funció session_start() i, en el moment en que el script ja no tingui que actualitzar l'array $_SESSION, ja podem executar la funció session_write_close(), fet que permetrà desbloquejar la execució d'altres scripts que estiguin aturats en el semàfor per a la funció session_start().

Evidentment, aquest problema de paralelisme es dona per a una mateixa sessió (un mateix client). Ja veurem si més endavant, en futures versions de PHP es permeten múltiples sessions per a un mateix client.

dimarts, 26 d’agost del 2008

Problemes apache2 Ubuntu 8 Hardy

Explico la solució del següent problema al instal·lar un servidor LAMP amb Ubuntu 8 Hardy:
- Al enllaçar a scripts php amb FireFox, no els executa sino que et demana amb quina aplicació els vols obrir, o be si els vols guardar.

Després de molt investigar i de vàries reinstal·lacions, la solució que m'ha funcionat es la següent:
- Al arxiu /etc/apache2/sites-enables/000-default, li faltaven indicar el ServerName i el DirectoryIndex.

El fitxer queda de la següent forma (en negreta les modificacions):
NameVirtualHost *
<Virtualhost *>
ServerAdmin webmaster@localhost
ServerName pochtatil
DocumentRoot /var/www/
DirectoryIndex index.php
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
...

Finalment només cal reiniciar l'apache:
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 start

Canviar etiqueta unitat USB

Tot això s'ha fet sota Ubuntu 8.04, amb escriptori Gnome.

Per canviar el nom que es veu a l'escriptori, cal canviar-ho des de un sistema Windows (quan descobreixi com fer-ho amb Linux, ja ho publicaré).

Per a muntar el dispositiu USB en un altre lloc, cal canviar el punt de muntatge amb el menú propietats que apareix clicant el botó dret sobre la incona del escriptori. El punt de muntatge cal que sigui un nom, sense caràcters estranys, i que el sistema penjarà del directori /media. Cal que aquest punt de muntatge no existeixi. Al desmuntar i tornar a muntar el dispositiu, ja funcionarà.

Si ens hem equivocat en aquest últim punt, i els sistema ens dona un error dient que no pot muntar el dispositiu doncs conté caràcters incorrectes al path de muntatge, ho podem arreglar amb el programa gconf-editor, modificant a la clau /system/storage/volumes el uuid que correspongui.

dijous, 21 d’agost del 2008

digikam a Gnome (problemes metadata)

digikam es un gestor fotogràfic molt complet, desenvolupat per a KDE. El podem fer funcionar a Gnome sense problemes (amb instal·ladors tipus Synaptic).

Si experimentem problemes amb la informació metadata de les imatges, es que ens falta instal·lar el paquet kdegraphics-kfile-plugins (amb el mateix Synaptic)

Font: http://www.digikam.org/drupal/node/166

Afegit el 14/04/2009: A partir de la versió 8.10 de Ubuntu sembla ser que això no funciona.

dimarts, 29 de juliol del 2008

Encriptar unitats USB amb Linux

Cal instal·lar el paquet cryptsetup.

Connectem la unitat USB, ja sigui un memory stick o un disc dur extern, i des de un terminal mirem el nom del dispositiu amb dmesg (per exemple, serà /dev/sdc).

Tot seguit particionem el dispositiu, si així ho volem.

Per encriptar una partició i donar-li format fat32 farem el següent: sudo luksformat /dev/sda1
Podem utilitzar la opció -t per donar format en un altre sistema de fitxers: sudo luksformat -t ntfs /dev/sda

El format LUKS ve de les sigles Linux Unified Key Support.

Es pot accedir des de Windows amb el software FreeOTFE.

Podem consultar el manual per a altres opcions.

Referències: http://ubuntu.wordpress.com/2006/01/24/use-an-encrypted-usb-drivepartition/
Avançat: HOWTO: Disk encryption with dm-crypt / LUKS and Debian

Connectar per USB un Nokia E51

Amb aquest article connectarem a internet des de Linux amb un NokiaE51 mitjançant cable USB.

Primer cal mirar el següent article, i seguir-lo al peu de la lletra:
http://amitksaha.blogspot.com/2008/01/using-nokia-e51-gsm-usb-modem-on-linux.html

Els fitxers que em funcionen be amb Vodafone son els següents:

Fitxer gprs
# $Id: gprs,v 1.4 2004/04/28 08:40:32 mcfrisk Exp $
#
# File:
# gprs
#
# Description:
# Serial cable, IrDA, Bluetooth and USB pppd options for GPRS phones.
# See 'man pppd' for detailed option descriptions.

# Most GPRS phones don't reply to LCP echo's
lcp-echo-failure 0
lcp-echo-interval 0

# Keep pppd attached to the terminal:
# Comment this to get daemon mode pppd
nodetach

# Debug info from pppd:
# Comment this off, if you don't need more info
debug

# Show password in debug messages
show-password

# Connect script:
# scripts to initialize the GPRS modem and start the connection,
# wvdial command is for Orange SPV while other phones should work with chat
connect /etc/ppp/peers/gprs-connect-chat
#connect "/usr/bin/wvdial --chat --config /etc/ppp/peers/gprs-wvdial.conf radiolinja_usb_orange_spv"

# Disconnect script:
# AT commands used to 'hangup' the GPRS connection.
disconnect /etc/ppp/peers/gprs-disconnect-chat

# Serial device to which the GPRS phone is connected:
# /dev/ttyS0 for serial port (COM1 in Windows),
# /dev/ircomm0 for IrDA,
# /dev/ttyUB0 for Bluetooth (Bluez with rfcomm running) and
# /dev/ttyUSB0 for USB
#/dev/ttyS0 # serial port one
#/dev/ttyS1 # serial port two
#/dev/ircomm0 # IrDA serial port one
#/dev/rfcomm0 # Bluetooth serial port one
#/dev/ttyUSB0 # USB serial device, for example Orange SPV
/dev/ttyACM0

# Serial port line speed
115200 # fast enough
#57600 # perhaps usefull with IrDA as some phones don't like
# speeds higher than this

# Hardware flow control:
# Use hardware flow control with cable, Bluetooth and USB but not with IrDA.
crtscts # serial cable, Bluetooth and USB, on some occations with IrDA too
#nocrtscts # IrDA

# Ignore carrier detect signal from the modem:
local

# IP addresses:
# - accept peers idea of our local address and set address peer as 10.0.0.1
# (any address would do, since IPCP gives 0.0.0.0 to it)
# - if you use the 10. network at home or something and pppd rejects it,
# change the address to something else
:10.0.0.1

# pppd must not propose any IP address to the peer!
noipdefault

# Accept peers idea of our local address
ipcp-accept-local

# Add the ppp interface as default route to the IP routing table
defaultroute

# Newer pppd's also support replacing the default route, if one is
# already present, when the GPRS connetion should be set as the default route
# to the network
replacedefaultroute

# DNS servers from the phone:
# some phones support this, some don't.
usepeerdns

# ppp compression:
# ppp compression may be used between the phone and the pppd, but the
# serial connection is usually not the bottleneck in GPRS, so the
# compression is useless (and with some phones need to disabled before
# the LCP negotiations succeed).
novj
nobsdcomp
novjccomp
nopcomp
noaccomp

# The phone is not required to authenticate:
noauth

# Username and password:
# If username and password are required by the APN, put here the username
# and put the username-password combination to the secrets file:
# /etc/ppp/pap-secrets for PAP and /etc/ppp/chap-secrets for CHAP
# authentication. See pppd man pages for details.
# Example, Radiolinja operator pap-secrets:
# "rlnet" * "internet" *
user ""

# The persist tries to reopen the connection if it is dropped. This
# is usefull for example with a Nokia 7650 which only manages to
# 'dial' with every second attempt or when the network likes to drop the
# connection every now and then. It's not fun when the over-night
# 'apt-get dist-upgrade -d -y' fails constantly...
#persist
#maxfail 99

# Asyncmap:
# some phones may require this option.
#asyncmap 0xa0000

# No magic:
# some phones may require this option.
#nomagic

# Require PAP authentication:
# some phones may require this option.
#require-pap

Fitxer gprs-connect-chat

#!/bin/sh
#
# $Id: gprs-connect-chat,v 1.2 2004/02/02 23:19:28 mcfrisk Exp $
#
# File:
# gprs-connect-chat
#
# Description:
# chat script to open Radiolinjas GPRS service with GPRS phones. If ppp
# negotiation stalls, try restarting the phone. To try with other GPRS
# operator setting, change the PDP contex setting. The settings work with
# most Ericsson models, but Nokia 8310 and 30 do not support QoS parameters
# with AT commands, so just delete those lines and it'll work.
#
# Set PDP context CID=1, protocol=IP, APN=internet:
# AT+CGDCONT=1,"IP","internet","",0,0
#
# Set CID=1 QoS requirements from the network, not supported by Nokia:
# AT+CGQREQ=1,0,0,0,0,0
#
# Set CID=1 minimum acceptable QoS parameters, not supported by Nokia:
# AT+CGQMIN=1,0,0,0,0,0
#
# 'Call' CID=1 (activate PDP context one, perform GPRS attach):
# ATD*99***1#
#
# Some phones like the Orange SPV (yes, the Microsoft Smartphone) use this
# dial string to start GPRS connection:
# ATD*99#
#
# The actual chat script:
exec chat \
TIMEOUT 5 \
ECHO ON \
ABORT '\nBUSY\r' \
ABORT '\nERROR\r' \
ABORT '\nNO ANSWER\r' \
ABORT '\nNO CARRIER\r' \
ABORT '\nNO DIALTONE\r' \
ABORT '\nRINGING\r\n\r\nRINGING\r' \
'' \rAT \
TIMEOUT 12 \
SAY "Press CTRL-C to close the connection at any stage!" \
SAY "\ndefining PDP context...\n" \
OK ATH \
OK ATE1 \
OK 'AT+CGDCONT=1,"IP","airtelnet.es","",0,0' \
OK ATD*99# \
TIMEOUT 22 \
SAY "\nwaiting for connect...\n" \
CONNECT "" \
SAY "\nConnected." \
SAY "\nIf the following ppp negotiations fail,\n" \
SAY "try restarting the phone.\n"

Fitxer gprs-disconnect-chat

#!/bin/sh
#
# $Id: gprs-disconnect-chat,v 1.3.2.2 2006/02/14 20:20:17 mcfrisk Exp $
#
# File:
# gprs-disconnect-chat
#
# send break
exec /usr/sbin/chat -V -s -S \
ABORT "BUSY" \
ABORT "ERROR" \
ABORT "NO DIALTONE" \
SAY "\nSending break to the modem\n" \
"" "\K" \
"" "\K" \
"" "\K" \
"" "\d\d+++\d\dATH" \
SAY "\nPDP context detached\n"

dijous, 10 de juliol del 2008

Passar de avi a dvd

Instal·lar mencoder, dvdauthor i k3b
Amb ubuntu seria:
sudo apt-get install mencoder
sudo apt-get install dvdauthor
sudo apt-get install k3b
sudo apt-get install mkisofs

Recodificar el fitxer .avi a .mpg (per a DVD PAL)
mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf
-vf scale=720:576,harddup -srate 48000 -af lavcresample=48000
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:
keyint=15:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 25 -o movie.mpg movie.avi

Crear els fitxers per al DVD
dvdauthor -t -o directorideldvd/ movie.mpg

Afegir més películes
dvdauthor -t -o directorideldvd/ movie2.mpg
dvdauthor -t -o directorideldvd/ movie3.mpg

Crear el contingut per al DVD
dvdauthor -o directorideldvd -T

Gravar el DVD
Utilitzant K3B, afegirem el contingut del directorideldvd i ho gravarem. Amb el mateix K3B podem crear una imatge ISO per després gravar-la directament.

També podem crear la imatge ISO amb mkisofs
mkisofs -dvd-video -o dvd.iso directorideldvd

Gràcies a:
http://hallecsyz.com.ar/2007/05/avi-dvd-con-kubuntu-linux-para-idiotas.html
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html
http://linuxparanabos.blogspot.com/2007/06/pasar-de-avi-dvd.html

divendres, 4 de juliol del 2008

Convertir de .mov a .avi

Utilitzant el programa mencoder
Instal·lar a ubuntu:
sudo apt-get install mencoder

I des de la consola:
mencoder -oac mp3lame -srate 22050 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=585:389 archivo.mov -o video_nuevo.avi

Font: http://danilo04.accionasolutions.net/convertir-de-mov-a-avi-en-linux/38/

Veure i escoltar correctament fitxers .mov

Provat a Ubuntu 8.04
Instal·lant el programa gxine funciona correctament