MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
November
Sun Mon Tue Wed Thu Fri Sat
   
13
     
2011
Months
Nov


Sun, Nov 13, 2011 8:22 pm

file_upload Perl Script

The PHP code I had been using to upload files to a website would not allow me to upload files more than a few MB in size, likely due to the MAX_FILE_SIZE setting for HTTP_POST_VARS. I decided I would use a Perl script, instead, for uploading files to the site.

I used a Perl script Uploading Files Using CGI and Perl Article written by Matt Doyle as the basis for my script with just some minor modifications. I changed the maximum allowed size for uploaded files from 5 MB to 15 MB. I also eliminated the code pertaining to the uploader's email address, since I didn't need that information, and removed all references to photos in the code, since I wanted to use the script for uploading any type of file not just photos. I added some code to provide file size information on the uploaded file when the upload completes, which I got from How do I display filesizes in a nice way? at Stuart's Useful Perl Pages.

When a file is uploaded, the script will now show something like the following when the upload is completed.

File upload completed!

File uploaded: opera-10.11.gcc4-static-qt3.pkg.gz
File size: 14.43 MB (15136905 bytes)

The Perl script, file_upload.cgi is available here

References:

  1. Uploading Files Using CGI and Perl Article
    By: Matt Doyle
    Date: March 14, 2008
    SitePoint >> Web Design, Web Development, Freelancing, Tech News and more
  2. How do I display filesizes in a nice way?
    Stuart's Useful Perl Pages
  3. How to get the size of a file in Perl using file test operators.
    Perl Programming & Tutorials from About.com

[/languages/perl] permanent link

Sun, Nov 13, 2011 3:03 pm

Determining the Network Interface Card (NIC) in a Linux System with lspci

I found that a network interface card (NIC) in a system was not picking up an IP via DHCP. When I checked the IP configuration for the card, I saw it had an invalid MAC address of all zeros.
$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:19 Base address:0xdead

The system had an Ethernet controller built into the motherboard. In such cases you can determing what Ethernet controller is being used by opening the system case or you can use the lspci command.

$ lspci | grep Ethernet
00:04.0 Ethernet controller: Silicon Integrated Systems [SiS] 190 Ethernet Adapt
er

On Linux systems, the lspi command displays information about Peripheral Component Interconnect (PCI) buses in the system and devices connected to them.

In the above case I could see that the system needed a Linux driver for a SiS 190 Ethernet Adapter.

NAME
       lspci - list all PCI devices

SYNOPSIS
       lspci [options]

DESCRIPTION
       lspci  is  a  utility for displaying information about PCI buses in the
       system and devices connected to them.

       By default, it shows a brief list of devices. Use the options described
       below  to  request  either a more verbose output or output intended for
       parsing by other programs.

       If you are going to report bugs in  PCI  device  drivers  or  in  lspci
       itself,  please  include  output  of "lspci -vvx" or even better "lspci
       -vvxxx" (however, see below for possible caveats).

       Some parts of the output, especially in the highly verbose  modes,  are
       probably  intelligible only to experienced PCI hackers. For exact defi
       nitions of the fields, please consult either the PCI specifications  or
       the header.h and /usr/include/linux/pci.h include files.

       Access  to  some  parts of the PCI configuration space is restricted to
       root on many operating systems, so the features of lspci  available  to
       normal  users  are limited. However, lspci tries its best to display as
       much as available and mark all other information with  <access  denied>
       text.


OPTIONS
   Basic display modes
       -m     Dump  PCI  device data in a backward-compatible machine readable
              form.  See below for details.

       -mm    Dump PCI device data in a machine readable form for easy parsing
              by scripts.  See below for details.

       -t     Show  a tree-like diagram containing all buses, bridges, devices
              and connections between them.


   Display options
       -v     Be verbose and display detailed information about all devices.

       -vv    Be very verbose and display more details.  This  level  includes
              everything deemed useful.

       -vvv   Be  even  more  verbose  and  display  everything we are able to
              parse, even if it doesn't look interesting at all  (e.g.,  unde
              fined memory regions).

       -k     Show kernel drivers handling each device and also kernel modules
              capable of handling it.  Turned on by default when -v  is  given
              in  the  normal  mode of output.  (Currently works only on Linux
              with kernel 2.6 or newer.)

       -x     Show hexadecimal dump of the standard part of the  configuration
              space (the first 64 bytes or 128 bytes for CardBus bridges).

       -xxx   Show  hexadecimal  dump of the whole PCI configuration space. It
              is available only to root as several PCI devices crash when  you
              try to read some parts of the config space (this behavior proba
              bly doesn't violate the PCI standard, but  it's  at  least  very
              stupid).  However,  such  devices are rare, so you needn't worry
              much.

       -xxxx  Show hexadecimal dump of the extended (4096-byte) PCI configura
              tion space available on PCI-X 2.0 and PCI Express buses.

       -b     Bus-centric  view. Show all IRQ numbers and addresses as seen by
              the cards on the PCI bus instead of as seen by the kernel.

       -D     Always show PCI domain numbers.  By  default,  lspci  suppresses
              them on machines which have only domain 0.


   Options to control resolving ID's to names
       -n     Show  PCI  vendor and device codes as numbers instead of looking
              them up in the PCI ID list.

       -nn    Show PCI vendor and device codes as both numbers and names.

       -q     Use DNS to query the central PCI ID database if a device is  not
              found  in the local pci.ids file. If the DNS query succeeds, the
              result is cached in ~/.pciids-cache and it is recognized in sub
              sequent  runs  even if -q is not given any more. Please use this
              switch inside automated scripts only with caution to avoid over
              loading the database servers.

       -qq    Same as -q, but the local cache is reset.

       -Q     Query the central database even for entries which are recognized
              locally.  Use this if you suspect that the  displayed  entry  is
              wrong.


   Options for selection of devices
       -s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]
              Show  only devices in the specified domain (in case your machine
              has several host bridges, they can either  share  a  common  bus
              number  space  or  each  of them can address a PCI domain of its
              own; domains are numbered from 0 to ffff), bus (0 to  ff),  slot
              (0  to  1f) and function (0 to 7).  Each component of the device
              address can be omitted or set to "*", both meaning "any  value".
              All  numbers  are  hexadecimal.  E.g., "0:" means all devices on
              bus 0, "0" means all functions of device 0  on  any  bus,  "0.3"
              selects  third  function of device 0 on all buses and ".4" shows
              only the fourth function of each device.

       -d [<vendor>]:[<device>]
              Show only devices with specified vendor and device ID. Both ID's
              are  given  in  hexadecimal  and may be omitted or given as "*",
              both meaning "any value".


   Other options
       -i <file>
              Use    <file>    as    the    PCI    ID    list    instead    of
              /usr/share/misc/pci.ids.

       -p <file>
              Use  <file> as the map of PCI ID's handled by kernel modules. By
              default, lspci uses  /lib/modules/kernel_version/modules.pcimap.
              Applies only to Linux systems with recent enough module tools.

       -M     Invoke  bus  mapping  mode which performs a thorough scan of all
              PCI devices, including those behind misconfigured bridges,  etc.
              This option gives meaningful results only with a direct hardware
              access mode, which usually  requires  root  privileges.   Please
              note that the bus mapper only scans PCI domain 0.

       --version
              Shows lspci version. This option should be used stand-alone.


   PCI access options
       The  PCI  utilities  use  the  PCI  library to talk to PCI devices (see
       pcilib(7) for details). You can use the following options to  influence
       its behavior:

       -A <method>
              The  library  supports  a  variety  of methods to access the PCI
              hardware.  By default, it uses the first  access  method  avail
              able, but you can use this option to override this decision. See
              -A help for a list of available methods and their descriptions.

       -O <param>=<value>
              The behavior of the  library  is  controlled  by  several  named
              parameters.   This  option allows to set the value of any of the
              parameters. Use -O help for a list of known parameters and their
              default values.

       -H1    Use  direct hardware access via Intel configuration mechanism 1.
              (This is a shorthand for -A intel-conf1.)

       -H2    Use direct hardware access via Intel configuration mechanism  2.
              (This is a shorthand for -A intel-conf2.)

       -F <file>
              Instead of accessing real hardware, read the list of devices and
              values of their configuration registers from the given file pro
              duced  by  an  earlier run of lspci -x.  This is very useful for
              analysis of user-supplied bug reports, because you  can  display
              the  hardware configuration in any way you want without disturb
              ing the user with requests for more dumps.

       -G     Increase debug level of the library.


MACHINE READABLE OUTPUT
       If you intend to process the output of lspci automatically, please  use
       one of the machine-readable output formats (-m, -vm, -vmm) described in
       this section. All other formats are likely to change  between  versions
       of lspci.


       All  numbers  are always printed in hexadecimal. If you want to process
       numeric ID's instead of names, please add the -n switch.


   Simple format (-m)
       In the simple format, each device is described on a single line,  which
       is  formatted  as  parameters  suitable  for passing to a shell script,
       i.e., values separated by whitespaces, quoted and escaped if necessary.
       Some  of the arguments are positional: slot, class, vendor name, device
       name, subsystem vendor name and subsystem name (the last two are  empty
       if  the  device  has no subsystem); the remaining arguments are option-
       like:


       -rrev  Revision number.


       -pprogif
              Programming interface.


       The relative order of positional arguments and  options  is  undefined.
       New  options can be added in future versions, but they will always have
       a single argument not separated from the option by any spaces, so  they
       can be easily ignored if not recognized.


   Verbose format (-vmm)
       The  verbose  output is a sequence of records separated by blank lines.
       Each record describes a single device by a sequence of lines, each line
       containing  a single `tag: value' pair. The tag and the value are sepa
       rated by a single tab character.  Neither the  records  nor  the  lines
       within a record are in any particular order.  Tags are case-sensitive.


       The following tags are defined:


       Slot   The    name    of    the   slot   where   the   device   resides
              ([domain:]bus:device.function).  This tag is always the first in
              a record.


       Class  Name of the class.


       Vendor Name of the vendor.


       Device Name of the device.


       SVendor
              Name of the subsystem vendor (optional).


       SDevice
              Name of the subsystem (optional).


       PhySlot
              The  physical  slot  where  the  device resides (optional, Linux
              only).


       Rev    Revision number (optional).


       ProgIf Programming interface (optional).


       Driver Kernel driver currently handling  the  device  (optional,  Linux
              only).


       Module Kernel  module  reporting  that  it  is  capable of handling the
              device (optional, Linux only).


       New tags can be added in future versions, so you should silently ignore
       any tags you don't recognize.


   Backward-compatible verbose format (-vm)
       In  this mode, lspci tries to be perfectly compatible with its old ver
       sions.  It's almost the same as the regular  verbose  format,  but  the
       Device  tag is used for both the slot and the device name, so it occurs
       twice in a single record. Please avoid using this  format  in  any  new
       code.


FILES
       /usr/share/misc/pci.ids
              A list of all known PCI ID's (vendors, devices, classes and sub
              classes). Maintained at http://pciids.sourceforge.net/, use  the
              update-pciids utility to download the most recent version.

       /usr/share/misc/pci.ids.gz
              If  lspci is compiled with support for compression, this file is
              tried before pci.ids.

       ~/.pciids-cache
              All ID's found in the DNS query mode are cached in this file.


BUGS
       Sometimes, lspci is not able to decode the configuration registers com
       pletely.  This usually happens when not enough documentation was avail
       able to the authors.  In such cases, it at least prints the  mark to
       signal that there is potentially something more to say. If you know the
       details, patches will be of course welcome.

       Access to the extended configuration space is currently supported  only
       by the linux_sysfs back-end.


SEE ALSO
       setpci(8), update-pciids(8), pcilib(7)


AUTHOR
       The PCI Utilities are maintained by Martin Mares <mj@ucw.cz>.



pciutils-3.1.7                  31 January 2010                       lspci(8)

[/os/unix/commands] permanent link

Sun, Nov 13, 2011 11:10 am

Mounting a USB Drive on a Linux System from the Command Line

If you need to manually mount a USB external drive, such as a flash drive, from the command line, i.e., a shell prompt, log into the root account for the system then issue the dmesg command feeding its results to grep and then use tail to get just the last line containing the word "SCSI", since if you just plugged the device into the system, that last line likely contains the relevant entry.
$ su - root
Password:
# dmesg | grep -i 'SCSI device' | tail --lines=1
SCSI device sdb: 7813120 512-byte hdwr sectors (4000 MB)

Since I know the flash drive I plugged into the system in this case is a 4 GB drive, I know that sdb is indeed the relevant drive designator.

Alternatively you could look for the information in /var/log/messages .

[root@example ~]# grep SCSI /var/log/messages | tail --lines=1
Nov 13 09:55:55 example kernel: SCSI device sdb: 7813120 512-byte hdwr secto
rs (4000 MB)

You can then use the information you obtained for the drive designator, in this case sdb to mount the drive. Note you might see other "sd" designators, such as sda, sdc, sdd, etc., or "hd" designators, such as hda, hdb, hdc, etc.

Use the mount command to mount the drive to an exising mount point, such as one beneath /mnt or /media. Unless a directory already exists that you wish to use, you could create a directory which you will use to access the contents of the USB drive. Let's suppose you want to use myusb for that directory; you then need to create the directory.

# mkdir /media/myusb

Presuming the file system on the flash drive is vfat, I could use the command below to mount the device at the mount point /media/myusb. You need to spcify the file system type with the -t option. Note: I use sdb1 rather than just the designator sdb, since I want to mount the first and, in this case, only partition, on the flash drive. The VFAT file system is a commonly used one for flash and other USB drives. It is a Microsoft created file system that allows the use of file names longer than an 8 character file name with a 3 character extension.

[root@example ~]# mount -t vfat /dev/sdb1 /media/myusb

I can then issue the mount command again without any parameters to verify the drive is mounted.

[root@example ~]# mount | grep sdb
/dev/sdb1 on /media/myusb type vfat (rw)

The rw on the output shows me that the drive is mounted in read/write mode rather than read only (ro) mode, so I could write to the drive as well as read from it.

You should then be able to access the drive using /media/myusb, or whatever you used for the path designator.

[root@frostdragon ~]# ls /media/myusb
aoss.txt  definitions

When you are finished with the drive, you should unmount it using the umount command prior to removing it from the system. You can also remove the directory you created for mounting it using the rmdir command, unless you will use that same directory for mounting it or other drives in the future.

[root@example ~]# umount /media/myusb
[root@example ~]# rmdir /media/myusb

References:

  1. VFAT
    Wikipedia, the free encyclopedia
  2. How to Mount USB flash drive from Command Line
    Date: December 1, 2007
    Linux Commando

[/os/unix/linux] permanent link

Sun, Nov 13, 2011 10:46 am

lsusb

To see a list of all USB devices connected to a Linux computer, use the lsusb command.
# lsusb
Bus 005 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 001 Device 002: ID 0781:5530 SanDisk Corp.
Bus 001 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000

Note: if you type lsusb and get a "command not found" message, the command may not be in your path. It may be in /sbin, so try specifying the path /sbin/lsusb.

To see more details on the USB devices attached to the system, use lsusb -v. If you don't specify a particular device you are interested in, you will get quite a bit of information. To restrict the information to a particular device, e.g., the SanDisk flash drive in the list above, you can specify a device and bus number, e.g., bus 001 and device number 002 in the above case, using the -s option.

# lsusb -v -s 1:2

Bus 001 Device 002: ID 0781:5530 SanDisk Corp.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x0781 SanDisk Corp.
  idProduct          0x5530
  bcdDevice            1.00
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           32
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk (Zip)
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               1
can't get device qualifier: Connection timed out
can't get debug descriptor: Connection timed out

If you move the USB device to another USB port on the system, you will see the bus number and device number combination change.

# lsusb
Bus 005 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 001 Device 007: ID 0781:5530 SanDisk Corp.
Bus 001 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000

The full list of options for the command is shown below.

# lsusb -h
lsusb: invalid option -- h
Usage: lsusb [options]...
List USB devices
  -v, --verbose
      Increase verbosity (show descriptors)
  -s [[bus]:][devnum]
      Show only devices with specified device and/or
      bus numbers (in decimal)
  -d vendor:[product]
      Show only devices with the specified vendor and
      product ID numbers (in hexadecimal)
  -D device
      Selects which device lsusb will examine
  -t
      Dump the physical USB device hierarchy as a tree
  -V, --version
      Show version of program

References:

  1. Linux / Unix Command: lsusb
    Linux Operating System and Linux Distributions

[/os/unix/commands] permanent link

Sun, Nov 13, 2011 10:45 am

PC Tools Alternate Opeating System Scanner (AOSS) version 2.0.5

PC Tools free Alternate Operating System Scanner allows you to boot a Microsoft Windows system with an alternate operating system on a CD. You can then scan the system for viruses from the CD, though I've found the utilitity of its anti-virus scanner to be very limited.

When I tried the virus scanning feature on a Dell Dimension 4550 PC that had Windows XP Home installed on the hard drive, the scanner didn't seem to be very effective, completing the scan in only 8 seconds and checking only 738 files out of the hundreds of thousands of files that existed on the Windows partition of the hard drive I scanned.

Total malware files:0
Total files:738
Scan time:8 seconds

The CD comes with a file manager that will allow you to access directories and files on your Microsoft Windows partitions on the hard drive. It also has "Disk Detonator", which will allow you to destroy partitions on the hard drive, if you wish.

You can get a shell prompt by choosing "System Shell" from the main menu, which will give you an ash shell provided via BusyBox, but the AOSS CD is lacking in standard Linux command line utilities. There is no scp nor ftp for transferring files over the network to another system. There is no links nor lynx one might use to access a web server to download or upload files. Wget and curl are also missing as are the standard network utilities such as ifconfig and netstat.

When I checked the contents of /proc/version, I saw that AOSS uses Ubuntu GNU/Linux for the operating system.

Linux version 2.6.39.4 (www-data@steve-aoss-ubuntu) (gcc version 4.4.1 (Ubuntu 4
.4.1-4ubuntu9) ) #1 SMP PREEMPT Mon Oct 31 11:26:05 EST 2011

References:

  1. Bootable Antivirus and AntiSpyware Software AOSS | PC Tools
    Free AntiVirus & AntiSpyware Software | PC Tools
  2. PC Tools Alternative Operating System AOS Freware Virus Scanner
    Date: May 27, 2010
    Free Antivirus Help Blog | Your source for the latest antivirus news and antivirus reviews

[/security/antivirus/pctools] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo