0

Howto create Loop Device on Linux

This mini howto explain how to create more loop device on your operating system.You need to create more loop device in some case like encrypted file system or HVM xen virtualization.  By default there are 7 devices available, named /dev/loop0 through to /dev/loop7.

INFORMATIONS
You can find the loop device like that :


1# ls -al /dev/loop*
2brw-r----- 1 root disk 7, 0 Mar 19 09:34 /dev/loop0
3brw-r----- 1 root disk 7, 1 Mar 19 09:34 /dev/loop1
4brw-r----- 1 root disk 7, 2 Mar 19 09:34 /dev/loop2
5brw-r----- 1 root disk 7, 3 Mar 19 09:34 /dev/loop3
6brw-r----- 1 root disk 7, 4 Mar 19 09:34 /dev/loop4
7brw-r----- 1 root disk 7, 5 Mar 19 09:34 /dev/loop5
8brw-r----- 1 root disk 7, 6 Mar 19 09:34 /dev/loop6
9brw-r----- 1 root disk 7, 7 Mar 19 09:34 /dev/loop7
The creation of the loop device is very simple but you have 2 options for this creation one is without reboot and the other one is with a reboot.


HOT CREATION
Creation of loop8 :

1# mknod -m640 /dev/loop8 b 7 8
2-m640 define the permission of the device
3/dev/loop8 define the name of the device
4b for the creation of the special block device
57 8 the number 7 AND 8 define the MAJOR AND the MINOR
Check if the loop is created

1# ls -l /dev/loop8
2brw-r----- 1 root root 7, 8 Oct 3 14:54 /dev/loop8
Now you have the applied the good owner on this device

1#chown root:disk /dev/loop8
Now you have to change the module limitation and reboot your system.
STANDARD CREATION
You have to modify this file /etc/udev/makedev.d/50-udev.nodes

01#vim /etc/udev/makedev.d/50-udev.nodes
02loop0
03loop1
04loop2
05loop3
06loop4
07loop5
08loop6
09loop7
10loop8
11parport0
12parport1
13parport2
14parport3
15net/tun
16ppp
17console
18null
19zero
Now you have to change the module limitation and reboot your system.

MODULE LIMITATION
In the kernel, you have to allow more creation of loop device.
There is an absolute maximum of 256 devices limited in the kernel. The default limit is set to 8.

01# modinfo loop
02filename: /lib/modules/2.6.18-53.1.14.el5.centos.plusxen/kernel/drivers/block/loop.ko
03alias: block-major-7-*
04license: GPL
05srcversion: 82DB6DB3DABF3B945D6394D
06depends:
07vermagic: 2.6.18-53.1.14.el5.centos.plusxen SMP mod_unload gcc-4.1
08parm: max_loop:Maximum number of loop devices (1-256) (int)
09module_sig: 883f35047d15787f0a982eee333b2d8112f51f09f68f09b79223a34983b3aef66820c08
10
11cc6e8cd3709f6d7c56171e5a579ee1ca2ca56349c56b983a7c46
Now you have to change this value with the modprobe.conf file.

1#vim /etc/modprobe.conf
2 ...
3options loop max_loop=64
4...
TIPS & COMMAND
The commande line losetup is used for set up and control loop device.

1# losetup
2usage:
3losetup loop_device # give info
4losetup -d loop_device # delete
5losetup -f # find unused
6losetup -a # list all used
7losetup -r # read-only loop
8losetup [-e encryption] [-o offset] [-r] {-f|loop_device} file # setup

0

Thin client + Slax + LCD TV= Media Center



I have a 1.5TB external hard drive(with its own power adapter) and three computers at home, it was not convenient if I want to get the files or save them to the external storage. So I planned to make my external hard drive to be shared in the home network:


There are at least three ways to set up this:
1) NAS drive;
2) Router with USB support;
3) File server;


I chose option 3 because I also need a light-weight computer to connect to my LCD TV, ideally can play movies.

After a long time googling, I bought HP Thin Client 5710 from the internet. Here are the specs:

Transmeta Efficeon 1.2GHz
256 MB Flash memory,
256 MB DDR SDRAM (upgraded to 512MB)
(24 MB of system RAM is reserved for processor usage)
ATI® Radeon 7000M
10/100 BaseT Fast Ethernet,

4 USB 2.0 ports, 1 serial, 1 parallel, 1 PS/2,
Sound: Internal amplified speaker, full 16-bit stereo, 44 kHz sample rate
Weight: 1.4Kg
Operating Temperature Range 0 to 40° C

The advantage of using this Thin client for this Job rather than a full size PC are its size (small and unobtrusive), tiny power consumption and the fact that the unit is totally silent ( apart from its Audio Output ).
 
I uses Ubuntu at work, so I would like to install one of the Ubuntu edition or light weight Debian. Because the internal flash memory is too small(256MB) and it already has a Genuine Windows XP Embedded SP2 installed which I don't want it to be ruined. So I will need to install Linux to the USB flash drive and boot the system from there(This needs USB2.0 support, if your Thin Client only has USB1.1, don't try it).

I tested the following Linux editions:
1) Ubuntu 10.10 (too slow, not usable);
2) Xubuntu 10.10 (better but still slow);
3) LXDE (fast, but can't play movie well);
4) Puppy Linux (fast, good);
5) Slax (fast, good);

I picked Slax as my Thin Client OS, I likes its module management system.




The basic Slax version includes the following modules:
001-core.lzm
002-xorg.lzm
003-desktop.lzm
004-kdesktop.lzm
005-koffice.lzm
006-devel.lzm
007-firefox.lzm

To build a file server that the files can be used by the Windows computer, you will need to install samba-3.4.4.lzm. After set up, all my computer's can access the external hard drive now through the wireless network, even play movies.

For the Thin Client itself with Slax, kplayer is enough to play AVI movies well without video latency issue, you are also able to load subtitles if you needed. But by default it does not support some video format like rm,rmvb etc. Install codecs-essential-20071007.lzm will load most of common codec in the system to allow you to watch different formats of movies.

There were still some problems after using Slax USB version, here are the solutions:

1)
The major problem I had from Slax was KDE mime type error, if you have this problem you will not be able to open any drives or folders as it will prompt an "open with" dialog box.

The mime type error is caused by a PosixOVL error. If you're running Slax from a FAT partition, it can't save file permissions the way it'd do on a Posix file system like EXT2 or XFS. PosixOVL is supposed to compensate for that by saving the permissions in individual files, but it's still quite buggy at this point.

The obvious solution is to not save your changes to a FAT partition.  The default Slax installation package already include a file called slaxsave.zip, unzip one of the files inside like save1024.zip(include a 1GB size slaxsave.dat file), this file represent a XFS-partition-image. Please see ReadMe file or click here for more information.

2)
512MB memory for this Thin Client is not enough sometimes, so you need to create a swap "partition" for the system. The "partition" here doesn't have to be a real physical one, we can make a swap file as a virtural swap partition. The steps are:

1 dd if=/dev/zero of=/mnt/hdc1/slax/swapfile bs=1M count=1024
2 mkswap /mnt/hdc1/slax/swapfile
3 swapon /mnt/hdc1/slax/swapfile
4 (adding this text in /etc/fstab file )
/mnt/hdc1/slax/swapfile none swap sw 0 0

(reference: how can create swap(virtual memory)in-live-slax)

0

Slax: solution to read only external hard drivers


When Slax auto detect External hard drives or USB keys but it permission defaulted to read only. Slax will not allow you to change the file permission. You will not be able to copy important files to the external hard drive.

Following steps will fix the permission problem.

Open Slax Konsole (Terminal Control) and type the following commands in

umount /mnt/sdb1
mount -t ntfs-3g /dev/sdb1 /mnt/sdb1 -o force

0

How to find USB VID/PID on various operating systems

source:http://www.freelabs.com/~whitis/USB_VID_PID.xhtml


Linux users can, of course, just use lsusb or usbview.   Run as root because on some systems, this doesn't show all the information otherwise.


lsusb (short form)



$ sudo lsusb

Bus 002 Device 049: ID eb1a:1760 eMPIA Technology, Inc.

Bus 002 Device 007: ID 04e8:323a Samsung Electronics Co., Ltd ML-1710 Printer

Bus 002 Device 005: ID 055f:0006 Mustek Systems, Inc. ScanExpress 1200 UB

Bus 002 Device 003: ID 0409:0058 NEC Corp. HighSpeed Hub

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 028: ID 0518:0001 EzKEY Corp. USB to PS2 Adaptor v1.09

Bus 001 Device 003: ID 046d:c03f Logitech, Inc. UltraX Optical Mouse

Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub



The "sudo" command is used to run the command as root (Adminstrative User) and is needed on systems where you don't normally log in as root.   If you are already root, you can just run lsusb without the sudo.   The "$" is just the command prompt and will vary depending on system configuration.   It is normally a "$" if you are an ordinary user or "#" if you are root and is often preceeded by the name of the current directory and sometimes the machine name and username.



   If you can't tell which device is the device you are interested in, unplug the device and repeat the listing then plug it back in and do the listing again.   Compare the listings; the device which disappears and then reappears from the listing is the device you want.


lsusb (long form)



   For this, you need the VID/PID obtained using the short form of lsusb.  In this example, it was "eb1a:1760". If you use lsusb -v without this, you get the long form listing for all devices which can be very long indeed and include a lot of irrelevant information.



$ sudo lsusb -v -d eb1a:1760


To save the information above to a file use:



  # lsusb -v eb1a:1760 > output.txt


The verbose listing not only decodes the USB device descriptor, it also decodes the class descriptors for hub, audio, HID, communications, chipcard, and video classes.

   If you are using a Knoppix or Ubunto Live CD, you need a way to share this information with the outside world.   You can run the firefox web browser (if your network adapter is working) and paste the information into a web form if that is all you need.    Or you can save the info on a usb flash drive or to a windows hard disk partition.

   If you create a USB flash drive to boot Knoppix or ubunto (directions on the net), create a small FAT32 partition on the flash drive so windows can easily see it.


usbview


usbview should not be mistaken for the similarly named utility on windows, although the names are the same and their purpose is similar.  Usbview is a GUI application.   It does not provide as much detail as lsusb -v but it provides it in a nice tree format.

Incidently, usbview also give you hints as to whether your device is plugged into a slow USB full speed port or a fast USB 2.0 high speed port.  Some devices don't work reliably or run slower when not plugged into a high speed port.  On my system the same device shows up under EHCI Host controller on a slow port but under USB 2.0 Hub Controller under EHCI host controller on a fast port.   If it shows up under an OHCI Host Controller or UHCI Host Controller, it is connected to a slow port.  Oddly, when plugged into the same port a webcam showed up under the EHCI Host Controller/USB2.0 Hub Controller but the keyboard shows up under OHCI Host Controller; this probably has something to do with emulation as the keyboard and mouse are used prior to booting.

usbview also reports the driver associated with each device, using the less than clear format "Name: uvcvideo"


 # sudo usbview &


/proc/bus/usb/devices

   cat /proc/bus/usb/devices will give a listing for all usb devices.     It is more detailed than a plain lsusb and more succinct than a lsusb -v.    You have to pick the approprate block of information (separated by blank lines) from the output.   This is the form that it submitted to www.linux-usb.org and is suitable for posting where you can't post the full lsusb -v output.    For a USB Video Class Device, it doesn't list supported resolutions, bitrates, encoding formats, or user controls which the lsusb -v listing does.


T:  Bus=02 Lev=02 Prnt=03 Port=01 Cnt=02 Dev#= 12 Spd=480 MxCh= 0

D:  Ver= 2.00 Cls=ef(unk. ) Sub=02 Prot=01 MxPS=64 #Cfgs=  1

P:  Vendor=eb1a ProdID=1760 Rev= 6.08

S:  Manufacturer=Infoxelle

S:  Product=Digital Microscope

S:  SerialNumber=VT1760

C:* #Ifs= 2 Cfg#= 1 Atr=80 MxPwr=500mA

A:  FirstIf#= 0 IfCount= 2 Cls=0e(video) Sub=03 Prot=00

I:* If#= 0 Alt= 0 #EPs= 1 Cls=0e(video) Sub=01 Prot=00 Driver=uvcvideo

E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Ivl=32ms

I:* If#= 1 Alt= 0 #EPs= 1 Cls=0e(video) Sub=02 Prot=00 Driver=uvcvideo

E:  Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms



lshw



   If you run lshw with the -numeric option, it will show the vendor device ID t the end of the product: line.   Leading zeros are supressed rather than printing as 4 digit hex.



/var/log/messages





    The file /var/log/messages contains syslog information including messages printed by device drivers when they recognize a device.    To use, unplug the device.   Then run:

  



       $ sudo tail -n 0 -f /var/log/messages

           or

       $  sudo tail -n 0 -f /var/log/messages | tee /tmp/logmessages


Wait ten seconds or so after you plug in the device and then hit control-C to stop the program.   The tail program with these options will just show you the new information as it is added to the file.    The tee program saves the output of the tail program in a file (/tmp/logmessages) while simultaneously showing the output to you.


Here is some sample output:


Apr 15 22:11:48 cervantes kernel: [1380806.451378] usb 2-8.2: USB disconnect, address 67

Apr 15 22:11:52 cervantes kernel: [1380812.296497] usb 2-8.2: new high speed USB device using ehci_hcd and address 68

Apr 15 22:11:52 cervantes kernel: [1380812.982274] usb 2-8.2: configuration #1 chosen from 1 choice

Apr 15 22:11:53 cervantes kernel: [1380812.982891] uvcvideo: Found UVC 1.00 device Digital Microscope (eb1a:1760)

Apr 15 22:11:53 cervantes kernel: [1380813.490404] input: Digital Microscope as /class/input/input1430

Apr 15 22:11:53 cervantes kernel: [1380813.490666] usb 2-8.2: New USB device found, idVendor=eb1a, idProduct=1760

Apr 15 22:11:53 cervantes kernel: [1380813.490673] usb 2-8.2: New USB device strings: Mfr=2, Product=1, SerialNumber=3

Apr 15 22:11:53 cervantes kernel: [1380813.490676] usb 2-8.2: Product: Digital Microscope

Apr 15 22:11:53 cervantes kernel: [1380813.490679] usb 2-8.2: Manufacturer: Infoxelle

Apr 15 22:11:53 cervantes kernel: [1380813.490681] usb 2-8.2: SerialNumber: VT1760

0

How To Tar Files And Folders Easy

0

DD comand examples

THE DD COMMAND


The dd command copies an amount of data block by block. The most basic syntax is:

Format
# dd if=xxxxx of=yyyyy bs=zzzzzz
( Where if=xxxxx is the source, of=yyyyy is the target and bs= both read and write zzzzz bytes at a time )


Examples:

Copy a hard disk partition to another hard disk:
# dd if=/dev/hda2 of=/dev/hdb2 bs=4096 conv=notrunc,noerror

If hdb2 doesn't exist, dd will start at the beginning of the disk, and create it. Be careful with order of if and of. You can write a blank disk to a good disk if you get confused. If you duplicate a smaller partition to a larger one, using dd, the larger one will now be formatted the same as the smaller one. And there will be no space left on the drive. The way around this is to use

Code:
rsync
, as described below.

To make an iso image of a CD: This duplicates sector for sector. MyCD.iso will be a hard disk image file of the CD.
Code:
dd if=/dev/hdc of=/home/sam/myCD.iso bs=2048 conv=sync,notrunc
You can mount the image like this:
Code:
mkdir /mnt/myCD
mount -o loop /home/sam/myCD.iso /mnt/myCD
Cloning an entire hard disk:
# dd if=/dev/hda of=/dev/hdb conv=notrunc,noerror


Copy a disk partition to a file on a different partition. (Do not copy a partition to the same partition !)
# dd if=/dev/hdb2 of=/home/test/partition.image bs=4096 conv=notrunc,noerror




Restore a disk partition from an image file:
# dd if=/home/test/partition.image of=/dev/hdb2 bs=4096 conv=notrunc,noerror



Mount a existing dd image:
# mount -o loop /path/your-dd-image /mnt/test


Copy MBR only of a hard drive:
# dd if=/dev/hda of=/home/test/MBR.image bs=446 count=1


Reverse:
# dd if=/home/test/MBR.image of=/dev/hda bs=446 count=1


Wipe a hard drive of all data ( you would want to boot from a cd to do this ):
# dd if=/dev/zero of=/dev/hda conv=notrunc


Make an iso image of a CD:
# dd if=/dev/hdc of=/home/test/TEST.iso bs=2048 conv=notrunc
( CD sectors are 2048 bytes, so this copies sector for sector. )

Copy a floppy disk:
# dd if=/dev/fd0 of=/home/test/floppy.image conv=notrunc

You can back up your MBR ( including partition table ):
# dd if=/dev/hda of=mbr.bin count=1


Put this on a floppy you make with:
# dd if=boot.img of=/dev/fd0


Boot from the floppy and restore the MBR:
# dd if=mbr.bin of=/dev/hda count=1


How to check dd progress
===================

By the way, if you need to restore a large image file and want to see what the progress is, you can use the following command from a new terminal session:

kill -USR1 $pid

You can find dd command's pid by using ps and grep commands like:

ps -A | grep dd

If you want to check an automatic progress, use "watch" command:
watch kill -USR1 $pid

0

Joining a Windows 7/ Windows 2008 R2 system to a Samba domain

This article suits for both Windows 7 and Windows 2008 R2(tested on 17/10/2010):

To join the domain for Windows 7 make sure you do the following steps:

  1. First you need to be running Samba v3.3.4 or later. Earlier versions have been reported to work, but there are some issues. 
  2. Next the Windows 7 client needs to have two registry keys added.

    HKLM\System\CurrentControlSet\Services\LanmanWorkstation\Parameters
    DWORD DomainCompatibilityMode   = 00000001
    DWORD DNSNameResolutionRequired = 00000000
  3. The following key needs to be changed or you will receive an error when trying to login using a domain accout of “The trust relationship between this workstation and the primary domain failed.”

    HKLM\SYSTEM\CurrentControlSet\services\Netlogon\Parameters
    DWORD RequireStrongKey  = 00000001
  4. DWORD RequireSignOrSeal = 00000001
Once these changes were made I was able to join the domain. I did receive an error on the join as shown in the following image, but the system seems to be working fine.

0

Linux permissions help

Linux permissions help

  • 1. What are file permissions
  • 2. File permissions notation
    • 2.1. Textual representation like "-rwxr--r--"
      • 2.1.1. Examples
    • 2.2. Numeric (octal) representation like "644"
      • 2.2.1. Examples
      • 2.2.2. Why there is a leading zero?
      • 2.2.3. Four meaningful digits like "4755"
  • 3. Difference in access permissions for files and folders
  • 4. Permissions required for web server
  • 5. Permissions set for FTP-uploaded files
  • 6. Set user ID, set group ID, sticky bit
    • 6.1. Numeric representation
    • 6.2. Textual representation
  • 7. Links

1. What are file permissions

Every file or folder in Linux has access permissions. There are three types of permissions (what allowed to do with a file):
  • read access
  • write access
  • execute access
Permissions are defined for three types of users:
  • the owner of the file
  • the group that the owner belongs to
  • other users
Thus, Linux file permissions are nine bits of information (3 types x 3 type of users), each of them may have just one of two values: allowed or denied.
Simply put, for each file it can be specified who can read or write from/to the file. For programs or scripts it also can be set if they are allowed to be executed.

2. File permissions notation

2.1. Textual representation like "-rwxr--r--"

It is used in Linux long directory listings. It consists of 10 characters. The first character shows the file type. Next 9 characters are permissions, consisting of three groups: owner, group, others. Each group consists of three symbols: rwx (in this order), if some permission is denied, then a dash "-" is used instead. Example:
-rwxr--r--
0123456789
  • Symbol in the position 0 ("-")is the type of the file. It is either "d" if the item is a directory, or "l" if it is a link, or "-" if the item is a regular file.
  • Symbols in positions 1 to 3 ("rwx") are permissions for the owner of the file.
  • Symbols in positions 4 to 6 ("r--") are permissions for the group.
  • Symbols in positions 7 to 9 ("r--") are permissions for others.
r Read access is allowed
w Write access is allowed
x Execute access is allowed
- Replaces "r", "w" or "x" if according access type is denied

2.1.1. Examples

-rwxr-xr-x File,
owner has read, write, execute permissions,
group: only read and execute permissions,
others: only read and execute permissions. 
dr-x------ Directory,
owner has read and execute access,
group and others have no access

To change the mode of a file, use the chmod command. The general form is
chmod X@Y file1 file2 ...
where: X is any combination of the letters `u' (for       owner), `g' (for group), `o' (for others), `a' (for all;       that is, for `ugo'); @ is either `+' to add permissions,       `-' to remove permissions, or `=' to assign permissions       absolutely; and Y is any combination of `r', `w', `x'.       Following are some examples:
chmod u=rx file        (Give the owner rx permissions, not w)
     chmod go-rwx file      (Deny rwx permission for group, others)
     chmod g+w file         (Give write permission to the group)
     chmod a+x file1 file2  (Give execute permission to everybody)
     chmod g+rx,o+x file    (OK to combine like this with a comma)

2.2. Numeric (octal) representation like "644"

If a numeric representation is used (like in chmod command, for example), then it is in the octal format (with the base of 8), and digits involved are 0 to 7. Octal format is used for the simplicity of understanding: every octal digit combines read, write and execute permissions together. Respective access rights for owner, group and others (in this order) are the last three digits of the numeric file permissions representation. Example: "0644". Here the second digit ("6" in the example) stands for rights of the owner, the third digit ("4" in the example) stands for rights of the group, the fourth digit ("4" in the example) stands for rights of others.
This table shows what numeric values mean:
Octal digit Text equivalent Binary value Meaning
0 --- 000 All types of access are denied
1 --x 001 Execute access is allowed only
2 -w- 010 Write access is allowed only
3 -wx 011 Write and execute access are allowed
4 r-- 100 Read access is allowed only
5 r-x 101 Read and execute access are allowed
6 rw- 110 Read and write access are allowed
7 rwx 111 Everything is allowed
We see that "1" stands for execute only, "2" stands for write only, "4" stands for read only. To combine the permissions you can simply add 1, 2 and 4 to get a needed combination. For instance, to get read and write permissions, you add 4 (read) and 2 (write), thus getting 6 (read and write). To get read and execute permissions, you add  4 (read) and 1 (execute), thus getting 5 (read and execute).

2.2.1. Examples

644 owner: read and write permissions,
group: only read permissions,
others: only read permissions. 
755 owner: read, write and execute permissions,
group: read and execute permissions,
others: read and execute permissions. 

2.2.2. Why there is a leading zero?

In programming, for instance, in C language, leading zero means that the value is in the octal format. Basically, it can be omitted. Owner, group and others rights are the last three digits of the permissions.

2.2.3. Four meaningful digits like "4755"

There are cases when you may come across four non-zero digits, in this case the first meaningful (non-zero) digit combines the following bits (in this order, high to low): SUID, SGID, sticky bit. We also know  that the last three are for owner, group and others.

3. Difference in access permissions for files and folders

Access permissions for files and folders mean different things from the user standpoint. The table below shows the difference.
Access type File Folder
Read If the file contents can be read If the directory listing can be obtained
Write If user or process can write to the file (change its contents) If user or process can change directory contents somehow: create new or delete existing files in the directory or rename files.
Execute If the file can be executed If user or process can access the directory, that is, go to it (make it to be the current working directory)

4. Permissions required for web server

Web server assigns the rights of the web-server-specific user, typically user "nobody", to the connected web client, as if "nobody" is connected to the web server. "Nobody" doesn't belong to your group and thus it inherits permissions that "others" have to your files.
  • For generic files such as html or images, etc you usually need to set 644 permissions. It is because "nobody" needs to read the file, and thus the file should be readable by others, hence 4 (read only) permissions for both group and others. For yourself you need a right to read and write (hence 6) to the file.
  • For scripts you need 755 rights. The script should be executable by "nobody". The script file should also be readable by "nobody", as the file is interpreted by an interpreter such as Perl and therefore must be readable. Thus it must combine read and execute permissions for "others", as "nobody" belongs to "others" group. For yourself you need to have also write access, getting 755 as a result.

5. Permissions set for FTP-uploaded files

When you upload files to your web hosting accounts, you become the owner of the files. Usually, by default files get 644 permissions, and depending on provider's FTP server configuration they may get different permissions in different situations. You also can change the file permissions with FTP client or by executing a chmod command in telnet.

6. Set user ID, set group ID, sticky bit

In addition to the basic permissions discussed above, there are also three bits of information defined for files in Linux:
  • SUID or setuid: change user ID on execution. If setuid bit is set, when the file will be executed by a user, the process will have the same rights as the owner of the file being executed.
  • SGID or setgid: change group ID on execution. Same as above, but inherits rights of the group of the owner of the file on execution. For directories it also may mean that when a new file is created in the directory it will inherit the group of the directory (and not of the user who created the file).
  • Sticky bit. It was used to trigger process to "stick" in memory after it is finished, now this usage is obsolete. Currently its use is system dependant and it is mostly used to suppress deletion of the files that belong to other users in the folder where you have "write" access to.

6.1. Numeric representation

Octal digit Binary value Meaning
0 000 setuid, setgid, sticky bits are cleared
1 001 sticky bit is set
2 010 setgid bit is set
3 011 setgid and sticky bits are set
4 100 setuid bit is set
5 101 setuid and sticky bits are set
6 110 setuid and setgid bits are set
7 111 setuid, setgid, sticky bits are set

6.2. Textual representation

SUID If set, then replaces "x" in the owner permissions to "s", if owner has execute permissions, or to "S" otherwise. Examples:
-rws------ both owner execute and SUID are set
-r-S------ SUID is set, but owner execute is not set
SGID If set, then replaces "x" in the group permissions to "s", if group has execute permissions, or to "S" otherwise. Examples:
-rwxrws--- both group execute and SGID are set
-rwxr-S--- SGID is set, but group execute is not set
Sticky If set, then replaces "x" in the others permissions to "t", if others have execute permissions, or to "T" otherwise. Examples:
-rwxrwxrwt both others execute and sticky bit are set
-rwxrwxr-T sticky bit is set, but others execute is not set

7. Links

0

Outputting from Postgres to CSV


\f ','
\a
\t
\o /home/john/moocow.csv
SELECT foo,bar FROM whatever;
\o
\q
 
If a field has newlines, this will break. You can do something like  this instead..... 
 
SELECT foo, bar, '"' || REPLACE(REPLACE(field_with_newilne, '\n', '\\n'), '"', '""') || '"'
FROM whatever;
 
Then you can import the data into another database if needed:
copy whatever(foo,bar) FROM
'/home/john/moocow.csv' DELIMITER ','
CSV HEADER; 

0

can't set default printer to Windows terminal server users

The problem can be happened when using Windows 2003 SP1 and terminal server.

Based on the solutions on the internet. Someone mentioned it could be related to problem in registry at [HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows] a advised to export this key from working user profile to non-working one, this works well.

But if you want to make all your users being able to set default printer, try this:

1.) Create some new account and set its profile. This will be a default profile for all accounts created from now on.
2.) Import this key to registry:

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows]
"DebugOptions"="2048"
"Documents"=""
"DosPrint"="no"
"load"=""
"NetMessage"="no"
"NullPort"="None"
"Programs"="com exe bat pif cmd"
"Device"="PDF,winspool,FPP2:"

0

How to use crontab

» Schedule tasks on Linux using crontab

If you've got a website that's heavy on your web server, you might want to run some processes like generating thumbnails or enriching data in the background. This way it can not interfere with the user interface. Linux has a great program for this called cron. It allows tasks to be automatically run in the background at regular intervals. You could also use it to automatically create backups, synchronize files, schedule updates, and much more. Welcome to the wonderful world of crontab.

Crontab

The crontab (cron derives from chronos, Greek for time; tab stands for table) command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically. To see what crontabs are currently running on your system, you can open a terminal and run:
sudo crontab -l
To edit the list of cronjobs you can run:
sudo crontab -e
This wil open a the default editor (could be vi or pico, if you want you can change the default editor) to let us manipulate the crontab. If you save and exit the editor, all your cronjobs are saved into crontab. Cronjobs are written in the following format:
* * * * * /bin/execute/this/script.sh

Scheduling explained

As you can see there are 5 stars. The stars represent different date parts in the following order:
  1. minute (from 0 to 59)
  2. hour (from 0 to 23)
  3. day of month (from 1 to 31)
  4. month (from 1 to 12)
  5. day of week (from 0 to 6) (0=Sunday)

Execute every minute

If you leave the star, or asterisk, it means every. Maybe that's a bit unclear. Let's use the the previous example again:
* * * * * /bin/execute/this/script.sh
They are all still asterisks! So this means execute /bin/execute/this/script.sh:
  1. every minute
  2. of every hour
  3. of every day of the month
  4. of every month
  5. and every day in the week.
In short: This script is being executed every minute. Without exception.

Execute every Friday 1AM

So if we want to schedule the script to run at 1AM every Friday, we would need the following cronjob:
0 1 * * 5 /bin/execute/this/script.sh
Get it? The script is now being executed when the system clock hits:
  1. minute: 0
  2. of hour: 1
  3. of day of month: * (every day of month)
  4. of month: * (every month)
  5. and weekday: 5 (=Friday)

Execute on workdays 1AM

So if we want to schedule the script to Monday till Friday at 1 AM, we would need the following cronjob:
0 1 * * 1-5 /bin/execute/this/script.sh
Get it? The script is now being executed when the system clock hits:
  1. minute: 0
  2. of hour: 1
  3. of day of month: * (every day of month)
  4. of month: * (every month)
  5. and weekday: 1-5 (=Monday til Friday)

Execute 10 past after every hour on the 1st of every month

Here's another one, just for practicing
10 * 1 * * /bin/execute/this/script.sh
Fair enough, it takes some getting used to, but it offers great flexibility.


Neat scheduling tricks

What if you'd want to run something every 10 minutes? Well you could do this:
0,10,20,30,40,50 * * * * /bin/execute/this/script.sh
But crontab allows you to do this as well:
*/10 * * * * /bin/execute/this/script.sh
Which will do exactly the same. Can you do the the math? ;)

Special words

If you use the first (minute) field, you can also put in a keyword instead of a number:
@reboot     Run once, at startup
@yearly     Run once  a year     "0 0 1 1 *"
@annually   (same as  @yearly)
@monthly    Run once  a month    "0 0 1 * *"
@weekly     Run once  a week     "0 0 * * 0"
@daily      Run once  a day      "0 0 * * *"
@midnight   (same as  @daily)
@hourly     Run once  an hour    "0 * * * *
Leave the rest of the fields empty so this would be valid:
@daily /bin/execute/this/script.sh

Storing the crontab output

By default cron saves the output of /bin/execute/this/script.sh in the user's mailbox (root in this case). But it's prettier if the output is saved in a separate logfile. Here's how:
*/10 * * * * /bin/execute/this/script.sh 2>&1 >> /var/log/script_output.log

Explained

Linux can report on different levels. There's standard output (STDOUT) and standard errors (STDERR). STDOUT is marked 1, STDERR is marked 2. So the following statement tells Linux to store STDERR in STDOUT as well, creating one datastream for messages & errors:
2>&1
Now that we have 1 output stream, we can pour it into a file. Where > will overwrite the file,  >> will append to the file. In this case we'd like to to append:
>> /var/log/script_output.log

Mailing the crontab output

By default cron saves the output in the user's mailbox (root in this case) on the local system. But you can also configure crontab to forward all output to a real email address by starting your crontab with the following line:
MAILTO="yourname@yourdomain.com"

Mailing the crontab output of just one cronjob

If you'd rather receive only one cronjob's output in your mail, make sure this package is installed:
aptitude install mailx
And change the cronjob like this:
*/10 * * * * /bin/execute/this/script.sh 2>&1 | mail -s "Cronjob ouput" yourname@yourdomain.com

Trashing the crontab output

Now that's easy:
*/10 * * * * /bin/execute/this/script.sh 2>&1 > /dev/null
Just pipe all the output to the null device, also known as the black hole. On Unix-like operating systems, /dev/null is a special file that discards all data written to it.

0

Some updates could not be installed

I just finished resolving that exact problem after I did a repair reinstall of XP (that included SP2). No updates could be installed on my computer after they were downloaded. I actually requested help from microsoft support (I'd heard that was difficult to obtain) and the guy responded today with the following 4 suggestions (suggestion 2 worked for me---yaaaa---hope one of them works for you):


After checking the Windows Update log which was uploaded automatically when submitting the case, I noticed that the error code 0x80004002 was encountered.

This error is most likely caused by one of the following conditions:

1. The Windows Update Temporary folder is corrupted.
2. The Windows Update Agent 3.0 is not installed properly.
3. The Windows Installer 3.1 is corrupted.

We can perform the following steps to get the issue resolved. After trying each suggestion, please go to the Windows Update site to check the issue. Thanks for your cooperation.

NOTE: Some third party programs can also affect the Windows Update service. If you are running any third party applications such as Spyblocker, Internet or web accelerators (programs designed to boost the speed of the Internet connection), security or anti-virus programs (Norton, McAfee, etc.), I recommend we temporarily disable or shut them down and then try accessing the Windows Update site later. Please be sure to enable them again when completing the update process.

Suggestion 1: Clean up Windows Update temporary folder

===========================================

1. Click Start, Run, type: cmd and press Enter. Please run the following command in the opened window.

Net stop WuAuServ

2. Click Start, Run, type: %windir% and press Enter.
3. In the opened folder, rename the folder SoftwareDistribution to Sdold.
4. Click Start, Run, type: cmd and press Enter. Please run the following command in the opened window.

Net start WuAuServ

If the issue still persists, please move on to suggestion 2.



Suggestion 2: Reinstall Windows Update Agent 3.0

======================================

1. Please download the file from the following link:
http://download.windowsupdate.com/v7/windowsupdate/redist/standalone/WindowsUpdateAgent30-x86.exe

2. Save the file to C: drive.

3. Click Start->Run, type: "C:\WindowsUpdateAgent30-x86.exe /wuforce" (without quotations) and then press Enter to install the Windows Update engine.

There is a space between "C:\WindowsUpdateAgent30-x86.exe" and "/wuforce"

Note: If you are using Windows Vista, please save the downloaded file to the D: drive, because the file cannot be launched directly from the C: root directory.

If it still does not work, please proceed to suggestion 3 to reinstall Windows Installer 3.1.



Suggestion 3: Reinstall Windows Installer 3.1

==================================

1. Press Start and choose Run.

2. Type in "cmd" (without quotation marks) and press OK.

3. In the command line, type in the following command and press Enter:

MSIexec /unregister
4. Then, type in the following command and press Enter:

MSIexec /regserver
After finishing the above steps, please check the result again. If the issue persists, please click Start, click Control Panel, and click Add/Remove Programs to check if Windows Installer 3.1 has been installed. If it has, please highlight and remove it. After that, please reinstall Windows Installer 3.1 from the following link.

Windows Installer 3.1 Redistributable (v2)
http://www.microsoft.com/downloads/d...DisplayLang=en

0

change postgresql time zone for west Australia

In west Australia, like Perth, when you are using postgresql database, you may need to change the time zone abbreviations to Australia:

change it for a session

postgres=# set timezone_abbreviations to 'Australia';

change it for database

postgres=# alter database DATABASENAME set timezone_abbreviations to 'Australia';

0

Blank and blank screen at Windows 2003 logon

when the system disk filled up. For some reason it zero out settings in the registry then you will get the following logon screen




You'll have to free up some space and perform registry edits remotely. Remember to backup your registry before performing any task like this.
 this is the edit required to get the screen back or close to standard.

[HKEY_USERS\.DEFAULT\Control Panel\Colors]
"ActiveBorder"="212 208 200"
"ActiveTitle"="10 36 106"
"AppWorkSpace"="128 128 128"
"Background"="102 111 116"
"ButtonAlternateFace"="181 181 181"
"ButtonDkShadow"="64 64 64"
"ButtonFace"="212 208 200"
"ButtonHilight"="255 255 255"
"ButtonLight"="212 208 200"
"ButtonShadow"="128 128 128"
"ButtonText"="0 0 0"
"GradientActiveTitle"="166 202 240"
"GradientInactiveTitle"="192 192 192"
"GrayText"="128 128 128"
"Hilight"="10 36 106"
"HilightText"="255 255 255"
"HotTrackingColor"="0 0 128"
"InactiveBorder"="212 208 200"
"InactiveTitle"="128 128 128"
"InactiveTitleText"="212 208 200"
"InfoText"="0 0 0"
"InfoWindow"="255 255 225"
"Menu"="212 208 200"
"MenuText"="0 0 0"
"Scrollbar"="212 208 200"
"TitleText"="255 255 255"
"Window"="255 255 255"
"WindowFrame"="0 0 0"
"WindowText"="0 0 0"

Reboot the server after the reg edit is completed.

0

Why windows not showing 4GB ram?

0

recreate RAID array

if one of the drives fail, replace the drive and rebuild the RAID-0 on the dead machine:

mdadm --stop /dev/md0
mdadm --create --verbose /dev/md0 --level=0 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1 --auto=md

0

psql: FATAL: Ident authentication failed for user "username" Error and Solution

Q. I've installed Postgresql under Red Hat Enterprise Linux 5.x server. I've created username / password and database. But when I try to connect it via PHP or psql using following syntax:
psql -d myDb -U username -W
It gives me an error that read as follows:
psql: FATAL: Ident authentication failed for user "username"
How do I fix this error?

A. To fix this error open PostgreSQL client authentication configuration file /var/lib/pgsql/data/pg_hba.conf :
# vi /var/lib/pgsql/data/pg_hba.conf
This file controls:
  1. Which hosts are allowed to connect
  2. How clients are authenticated
  3. Which PostgreSQL user names they can use
  4. Which databases they can access
By default Postgresql uses IDENT-based authentication. All you have to do is allow username and password based authentication for your network or webserver. IDENT will never allow you to login via -U and -W options. Append following to allow login via localhost only:
local all all trust
host all 127.0.0.1/32 trust
Save and close the file. Restart Postgresql server:
# service postgresql restart
Now, you should able to login using following command:
$ psql -d myDb -U username -W


article source: http://www.cyberciti.biz/faq/psql-fatal-ident-authentication-failed-for-user/ 

0

Regular Expressions in PostgreSQL


Every programmer should embrace and use regular expressions (INCLUDING Database programmers). There are many places where regular expressions can be used to reduce a 20 line piece of code into a 1 liner. Why write 20 lines of code when you can write 1.

Regular expressions are a domain language just like SQL. Just like SQL they are embedded in many places. You have them in your program editor. You see it in sed, grep, perl, PHP, Python, VB.NET, C#, in ASP.NET validators and javascript for checking correctness of input. You have them in PostgreSQL as well where you can use them in SQL statements, domain definitions and check constraints. You can mix regular expressions with SQL. When you mix the two domain languages, you can do enchanting things with a flip of a wrist that would amaze your less informed friends. Embrace the power of domain languages and mix it up. PostgreSQL makes that much easier than any other DBMS we can think of.
For more details on using regular expressions in PostgreSQL, check out the manual pages Pattern Matching in PostgreSQL
The problem with regular expressions is that they are slightly different depending on what language environment you are running them in. Different enough to be frustrating. We'll just focus on their use in PostgreSQL, though these lessons are applicable to other environments.

Common usages

We are going to go backwards a bit. We will start with demonstrations of PostgreSQL SQL statements that find and replace things and list things out with regular expressions. For these exercises we will be using a contrived table called notes, which you can create with the following code.
CREATE TABLE notes(note_id serial primary key, description text); INSERT INTO notes(description) VALUES('John''s email address is johnny@johnnydoessql.com. Priscilla manages the http://www.johnnydoessql.com site. She also manages the site http://jilldoessql.com and can be reached at 345.678.9999 She can be reached at (123) 456-7890 and her email address is prissy@johnnydoessql.com or prissy@jilldoessql.com.'); INSERT INTO notes(description) VALUES('I like ` # marks and other stuff that annoys militantdba@johnnydoessql.com. Militant if you have issues, give someone who gives a damn a call at (999) 666-6666.');

Regular Expressions in PostgreSQL

PostgreSQL has a rich set of functions and operators for working with regular expressions. The ones we commonly use are ~, regexp_replace, and regexp_matches.
We use the PostgreSQL g flag in our use more often than not. The g flag is the greedy flag that returns, replaces all occurrences of the pattern. If you leave the flag out, only the first occurrence is replaced or returned in the regexp_replace, regexp_matches constructs. The ~ operator is like the LIKE statement, but for regular expressions.

Destroying information

The power of databases is not only do they allow you to store/retrieve information quickly, but they allow you to destroy information just as quickly. Every database programmer should be versed in the art of information destruction.
 -- remove email addresses if description has email address 
 UPDATE notes SET description = regexp_replace(description, 
       E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]{2,4}', 
        '---', 'g') 
        WHERE description 
        ~ E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]{2,4}'; 
        
 -- remove website urls if description has website urls 
 -- matches things like http://www.something.com or http://something.com

 UPDATE notes SET description = regexp_replace(description, 
       E'http://[[[:alnum:]]+.]*[[:alnum:]]+[.][[:alnum:]]+', 
        E'--', 'g') 
        WHERE description 
        ~ E'http://[[[:alnum:]]+.]*[[:alnum:]]+[.][[:alnum:]]+'; 

-- remove phone numbers if description 
-- has phone numbers e.g. (123) 456-7890 or 456-7890 or 123.456.7890
UPDATE notes SET description = regexp_replace(description, 
      E'[\(]{0,1}[0-9]{3}[\).-]{0,1}[[:space:]]*[0-9]{3}[.-]{0,1}[0-9]{4}',
        '---', 'g') 
        WHERE description 
        ~ E'[\(]{0,1}[0-9]{3}[\).-]{0,1}[[:space:]]*[0-9]{3}[.-]{0,1}[0-9]{4}'; 

-- set anything to single space that is not not a \ ( ) & * /,;. > < space or alpha numeric        
UPDATE notes set description = regexp_replace(description, E'[^\(\)\&\/,;\*\:.\>\<[:space:]a-zA-Z0-9-]', ' ') 
  WHERE description ~ E'[^\(\)\&\/,;\*\:.\<\>[:space:]a-zA-Z0-9-]';
  
-- replace high byte characters with space 
-- this is useful if you have your database in utf8 and you often need to use latin1 encoding
-- and you have a table that shouldn't have high byte characters 
-- such as junk you get from scraping websites
-- high byte characters don't convert down to latin1
UPDATE notes SET description = regexp_replace(description,E'[^\x01-\x7E]', ' ', 'g')
WHERE description ~ E'[^\x01-\x7E]';

Getting list of matches

These examples use similar to our destroy but show us in a table, a list of stuff that match. Here we use our favorite PostgreSQL regexp_matches function.


-- list first email address from each note --
SELECT note_id, 
  (regexp_matches(description, 
    E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+'))[1]  As email
FROM notes
WHERE description ~ E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+'
ORDER By note_id, email;
-- result
 note_id |             email
---------+-------------------------------
       1 | johnny@johnnydoessql.com
       2 | militantdba@johnnydoessql.com


--list all email addresses
-- note this uses the PostgreSQL 8.4 unnest construct 
-- to convert the array returned to a table
SELECT note_id, 
  unnest(
    regexp_matches(description, 
    E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+', 'g')
  ) As email
FROM notes
WHERE description ~ E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+'
ORDER By note_id, email;

-- returns
 note_id |             email
---------+-------------------------------
       1 | johnny@johnnydoessql.com
       1 | prissy@jilldoessql.com
       1 | prissy@johnnydoessql.com
       2 | militantdba@johnnydoessql.com

Parts of a Regular Expresssion

Here we will just cover what we consider the parts you need to know if you don't have the patience or memory to remember more. Regular expressions are much richer than our simplified view of things. There is the great backreferencing feature we won't get into which allows you to reference an expression and use it as part of your replacement expression.
PartExample
Classes []Regular expression classes are a set of characters that you can treat as interchangeable. They are formed by enclosing the characters in a bracket. They can also have nested classes. For example [A-Za-z] will match any letter between A-Z and a-z. [A-Za-z[:space:]] will match those plus white spaces in PostgreSQL. If you need to match a regular expression character such as ( then you escape it with \. so [A-Za-z\(\)] will match A thru Z a thru z and ( ). Classes can contain other classes and expressions as members.
.The famous . matches any character. So the infamous .* means one or more of anything.
Quantity {} + *You denote quantities with {}, +, * + means 1 or more. * means 0 or more and {} to denote allowed quantity ranges. [A-Za-z]{1,5} means you can have between 1 and 5 alpha characters in and expression for it to be a match.
()This is how you denote a subexpression. A subexpression can be composed of multiple classes etc and can be backreferenced. They define a specific sequence of characters.
[^members here]This is the NOT operator in regular expressions so for example [^A-Za-z] will match any character that is not in the alphabet.
Special classes[[:alnum:]] any alphanumeric, [[:space:]] any white space character. There are others, but those are the most commonly used.


 Article source: http://www.postgresonline.com/journal/index.php?/archives/152-Regular-Expressions-in-PostgreSQL.html