Onion's Crunch

Blog dedicado a la administracion bajo linux y a la programacion 2RDP, es decir como van llegando los requerimientos, resolver sin derecho a pataleo..... Tambien algunos tips para los perlceros, phpceros, javaceros, mysqlceros, postgresceros, apacheceros, entre otros....

martes, febrero 22, 2005

Programacion Perl: Funciones de Fecha

Como no me quede tranquilo en ver como se trabajaba con las funciones de fecha en bash me tome la libertad de hacer lo propio en perl. Aca esta un ejemplo que muestra los dias del mes y el dia siguiente empleando algunas rutinas definidas en la libreria Date::Calc, POSIX y Time::Local.

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Date::Calc qw(Add_Delta_Days);
  4. use Date::Calc qw(Add_Delta_YMDHMS);
  5. use POSIX qw(strftime);
  6. use Time::Local;
  7. my ($oyear, $omonth, $oday,$ohour,$omin,$osec) = (2005,01,01,0,0,0);
  8. my ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds) = (0,0,1,0,0,0);
  9. my ($year,$month,$day, $hour,$min,$sec) = ($oyear, $omonth, $oday,$ohour,$omin,$osec);
  10. while ($omonth == $month){
  11. ($oyear, $omonth, $oday,$ohour,$omin,$osec) = ($year,$month,$day, $hour,$min,$sec);
  12. ($year,$month,$day, $hour,$min,$sec) = Add_Delta_YMDHMS($oyear,$omonth,$oday, $ohour, $omin, $osec, $D_y,$D_m,$D_d, $Dh,$Dm,$Ds);
  13. my $ctime = timelocal(0, 0, 0, $oday, $omonth-1, $oyear);
  14. my $ntime = timelocal(0, 0, 0, $day, $month-1, $year);
  15. my $cdate = POSIX::strftime( "%Y-%m-%d", localtime($ctime));
  16. my $ndate = POSIX::strftime( "%Y-%m-%d", localtime($ntime));
  17. print "$cdate,$ndate\n";
  18. }

El resultado por consola es algo como esto:
2005-01-01,2005-01-02
2005-01-02,2005-01-03
2005-01-03,2005-01-04
2005-01-04,2005-01-05
2005-01-05,2005-01-06
2005-01-06,2005-01-07
2005-01-07,2005-01-08
2005-01-08,2005-01-09
2005-01-09,2005-01-10
2005-01-10,2005-01-11
2005-01-11,2005-01-12
2005-01-12,2005-01-13
2005-01-13,2005-01-14
2005-01-14,2005-01-15
2005-01-15,2005-01-16
2005-01-16,2005-01-17
2005-01-17,2005-01-18
2005-01-18,2005-01-19
2005-01-19,2005-01-20
2005-01-20,2005-01-21
2005-01-21,2005-01-22
2005-01-22,2005-01-23
2005-01-23,2005-01-24
2005-01-24,2005-01-25
2005-01-25,2005-01-26
2005-01-26,2005-01-27
2005-01-27,2005-01-28
2005-01-28,2005-01-29
2005-01-29,2005-01-30
2005-01-30,2005-01-31
2005-01-31,2005-02-01

Espero sirva de algo para todo los perl ceros!!!



Programacion Bash: Funciones de Fechas

He aqui un codigo para trabajar con las fechas en modo bash. Requerimientos naturalmente disponer de un soporte para bash bien sea basado en win32 o en su defecto tener linux en su pc. La aplicacion que veran a continuación permite avanzar hasta el mes siguiente dia por dia, desde la fecha actual.

  1. #!/bin/sh
  2. #
  3. cmonth=`/bin/date -d '1 day ago' +%Y-%m`
  4. nmonth=`/bin/date -d '1 day next' +%Y-%m`
  5. i=1
  6. while [ "$cmonth" = "$nmonth" ]
  7. do
  8. echo "$nmonth-$i"
  9. i=`expr $i + 1`
  10. nmonth=`/bin/date -d "$i day next" +%Y-%m`
  11. done

Es una aplicacion bastante elemental y puede ser muy util para todos los bash ceros del planeta....

Algunos scripts interesantes en este sentido:
Advanced Bash-Scripting Guide
Linux Shell Scripting Tutorial


Que lo disfrute...!!

viernes, febrero 11, 2005

Network Services Checker

Para aquellos que deseen monitorear los servicios de su red sin tener que hacer un mayor esfuerzo, pueden recurrir a NSC

Requerimientos:
- Apache
- PHP 4.x o suprior
- Linux (preferiblemente)

La instalacion es bastante sencilla, descargan la aplicacion desde:
aqui y la expanden en una carpeta visible desde el apache.

Para agregar nuevos servicios pueden editar el archivo: network_services_checker.php

Y colocan los servicios que deseen agregar, por ejemplo:
var $monitors = array(
"PING" => array(
"defaultPort" => "0"
),
"SSH" => array(
"defaultPort" => "22"
),
"DNS" => array(
"defaultPort" => "53"
),
"HTTP" => array(
"defaultPort" => "80"
),
"MYSQL" => array(
"defaultPort" => "3306"
),
"POSTGRES" => array(
"defaultPort" => "5432"
),
"FTP" => array(
"defaultPort" => "21"
),
"SSH" => array(
"defaultPort" => "22"
),
"POP3" => array(
"defaultPort" => "110"
),
"WEBMIN" => array(
"defaultPort" => "10000"
),
"SMTP" => array(
"defaultPort" => "25"
)
);

Lo demas es pan comido, abren su browser en la direccion donde esta instalado su aplicacion, en mi caso:
http://localhost/web/NSC/network_services_checker_frontend.php

Y ya tienen juguete nuevo para monitorear los servicios.

Aqui un screen shot de la aplicacion:

viernes, febrero 04, 2005

Linux Hardware Lister

Hoy revisando en freshmeat me tope con una aplicacion bien simpatica para conocer el hardware de la maquina. Todo el que se ha topado alguna ves con instalaciones bajo linux y necesita compilar el kernel o se hace un trabajo de inventario sabe cuan util puede ser.

Este utilitario funciona bajo linux, se llama lshw, podemos ver los detalles en http://ezix.sourceforge.net/ . Para variar no aguante la tentación para probarlo asi que me tome la libertad de instalarlo.

En gentoo:
emerge -v lshw

En debian:
apt-get install lshw

QUE COMPLICADO NO ? bueno para completar usarlo es bien sencillo, si queremos generar un reporte basta con hacer:

lshw -html hardware.html

Aca le indicamos que nos genere el reporte de hardware y la salida la formatee en html

Anexo el reporte del perolito que tengo en la oficina.......

------------------------------------------------------------------------------------
zeratul

description: Desktop Computer
product: HP d220 MT (DC527A)
vendor: Hewlett-Packard
serial: MXD33806Y0
capabilities: smbios-2.3 dmi-2.3
configuration:
chassis=desktop
uuid=9EC80DC1-85F0-D711-80CC-517B4801761B
core
description: Motherboard
product: 0888h
vendor: Lite-On Tech.
physical id: 0
serial: 01234567
slot: KEYBOARD
firmware
description: BIOS
vendor: American Megatrends Inc.
physical id: 0
version: 1.02 (05/09/2003)
size: 64KB
capacity: 448KB
capabilities: isa pci pnp apm upgrade shadowing escd cdboot bootselect socketedrom edd int13floppy360 int13floppy1200 int13floppy720 int13floppy2880 int5printscreen int9keyboard int17printer int10video acpi usb agp ls120boot zipboot biosbootspecification
cpu
description: CPU
product: Intel(R) Pentium(R) 4 CPU 2.40GHz
vendor: Intel Corp.
physical id: 4
bus info: cpu@0
version: 15.2.9
slot: mPGA-478
size: 2400MHz
capacity: 4GHz
clock: 133MHz
capabilities: fpu fpu_exception wp vme de tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid xtpr
configuration:
id=0
cache:0
description: L1 cache
physical id: 5
slot: Internal Cache
size: 8KB
capacity: 1MB
clock: 25MHz (40ns)
capabilities: pipeline-burst synchronous internal write-back data
cache:1
description: L2 cache
physical id: 6
slot: Internal Cache
size: 512KB
capacity: 1MB
clock: 25MHz (40ns)
capabilities: synchronous internal write-back unified
memory
description: System memory
physical id: 1
size: 503MB
pci
description: Host bridge
product: 82845G/GL[Brookdale-G]/GE/PE DRAM Controller/Host-Hub Interface
vendor: Intel Corp.
physical id: e0000000
bus info: pci@00:00.0
version: 03
clock: 33MHz
resources:
iomemory:e0000000-e7ffffff
display
description: VGA compatible controller
product: 82845G/GL[Brookdale-G]/GE Chipset Integrated Graphics Device
vendor: Intel Corp.
physical id: 2
bus info: pci@00:02.0
version: 03
size: 128MB
clock: 33MHz
capabilities: vga bus_master cap_list
resources:
iomemory:d0000000-d7ffffff
iomemory:dff80000-dfffffff
irq:177
usb:0 UNCLAIMED
description: USB Controller
product: 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) USB UHCI Controller #1
vendor: Intel Corp.
physical id: 1d
bus info: pci@00:1d.0
version: 02
clock: 33MHz
capabilities: uhci bus_master
resources:
ioport:e400-e41f
irq:177
usb:1 UNCLAIMED
description: USB Controller
product: 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) USB UHCI Controller #2
vendor: Intel Corp.
physical id: 1d.1
bus info: pci@00:1d.1
version: 02
clock: 33MHz
capabilities: uhci bus_master
resources:
ioport:e800-e81f
irq:185
usb:2 UNCLAIMED
description: USB Controller
product: 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) USB UHCI Controller #3
vendor: Intel Corp.
physical id: 1d.2
bus info: pci@00:1d.2
version: 02
clock: 33MHz
capabilities: uhci bus_master
resources:
ioport:ec00-ec1f
irq:193
usb:3
description: USB Controller
product: 82801DB/DBM (ICH4/ICH4-M) USB2 EHCI Controller
vendor: Intel Corp.
physical id: 1d.7
bus info: pci@00:1d.7
version: 02
clock: 33MHz
capabilities: ehci bus_master cap_list
configuration:
driver=ehci_hcd
resources:
iomemory:dff7bc00-dff7bfff
irq:201
usbhost
product: Intel Corp. 82801DB/DBM (ICH4/ICH4-M) USB 2.0 EHCI Controller
vendor: Linux 2.6.9-rc2 ehci_hcd
physical id: 1
bus info: usb@1
logical name: usb1
version: 2.06
capabilities: usb-2.00
configuration:
driver=hub
maxpower=0mA
slots=6
speed=480.0MB/s
pci
description: PCI bridge
product: 82801 PCI Bridge
vendor: Intel Corp.
physical id: 1e
bus info: pci@00:1e.0
version: 82
clock: 33MHz
capabilities: pci normal_decode bus_master
network
description: Ethernet controller
product: BCM4401 100Base-T
vendor: Broadcom Corporation
physical id: a
bus info: pci@03:0a.0
logical name: eth0
version: 01
serial: 00:02:e3:32:29:0e
size: 100Mbps
clock: 33MHz
capabilities: bus_master cap_list mii autonegotiation 100bt-fd 100bt 10bt-fd 10bt ethernet physical
configuration:
autonegociated=100bt
broadcast=yes
driver=b44
driverversion=0.94
duplex=half
ip=192.168.3.101
link=yes
multicast=yes
resources:
iomemory:dfdfe000-dfdfffff
irq:185
isa UNCLAIMED
description: ISA bridge
product: 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge
vendor: Intel Corp.
physical id: 1f
bus info: pci@00:1f.0
version: 02
clock: 33MHz
capabilities: isa bus_master
ide
description: IDE interface
product: 82801DB (ICH4) IDE Controller
vendor: Intel Corp.
physical id: 1f.1
bus info: pci@00:1f.1
version: 02
clock: 33MHz
capabilities: ide bus_master
configuration:
driver=PIIX_IDE
resources:
ioport:fc00-fc0f
iomemory:1f800000-1f8003ff
irq:193
ide:0
description: IDE Channel 0
physical id: 0
bus info: ide@0
logical name: ide0
clock: 33MHz
disk
description: ATA Disk
product: Maxtor 2F040L0
vendor: Maxtor
physical id: 0
bus info: ide@0.0
logical name: /dev/hda
version: VAM51JJ0
serial: F1D8ZVEE
size: 38GB
capacity: 38GB
capabilities: ata dma lba iordy smart security pm apm
configuration:
apm=off
mode=udma6
smart=on
ide:1
description: IDE Channel 1
physical id: 1
bus info: ide@1
logical name: ide1
clock: 33MHz
cdrom
product: LITE-ON LTR-48246S
physical id: 0
bus info: ide@1.0
logical name: /dev/hdc
capacity: 1023GB
disk
description: ATA Disk
product: ST380023A
vendor: Seagate
physical id: 1
bus info: ide@1.1
logical name: /dev/hdd
version: 3.31
serial: 3KB1BZF3
size: 74GB
capacity: 74GB
capabilities: ata dma lba iordy smart security pm
configuration:
mode=udma4
smart=on
serial
description: SMBus
product: 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) SMBus Controller
vendor: Intel Corp.
physical id: 1f.3
bus info: pci@00:1f.3
version: 02
clock: 33MHz
configuration:
driver=i801_smbus
resources:
ioport:c00-c1f
irq:209
multimedia
description: Multimedia audio controller
product: 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) AC'97 Audio Controller
vendor: Intel Corp.
physical id: 1f.5
bus info: pci@00:1f.5
version: 02
clock: 33MHz
capabilities: bus_master cap_list
configuration:
driver=Intel ICH
resources:
ioport:e000-e0ff
ioport:dc00-dc3f
iomemory:dff7ba00-dff7bbff
iomemory:dff7b900-dff7b9ff
irq:209
scsi
physical id: 2
bus info: scsi@0
logical name: scsi0
capabilities: emulated
channel
description: SCSI Channel 0
physical id: 0
bus info: scsi@0.0
cdrom
description: CD-R/CD-RW writer
product: LTR-48246S
vendor: LITE-ON
physical id: 0
bus info: scsi@0.0:0.0
logical name: /dev/cdrom
logical name: /dev/dvd
logical name: /dev/sr0
version: SPS3
capabilities: removable audio cd-r cd-rw
configuration:
ansiversion=2
network:0 DISABLED
description: Ethernet interface
physical id: 1
bus info: vpîÿ¿›; ì·pîÿ¿ îÿ¿@Øì·ô¿ì·@Øì·˜è ˆîÿ¿•à·@
logical name: bond0
capabilities: mii ethernet physical
configuration:
broadcast=yes
driver=bonding
driverversion=2.6.0
firmware=2
master=yes
multicast=yes
network:1 DISABLED
description: Ethernet interface
physical id: 2
logical name: dummy0
serial: de:7a:78:87:bf:f1
capabilities: ethernet physical
configuration:
broadcast=yes

------------------------------------------------------------------------------------