Raw printing in Linux is achieved by issuing the command and piping the result to /dev/lp0. For example:
# ls -l > /dev/lp0
Raw printing is useful if you want to take advantage of fast printing using the default fonts of the printer. More often, this is useful if you will be printing under a dot matrix printer.
Furthermore, you can also issue printer codes to the printer to make condensed printing as follows:
# echo -ne '\033\017' >> /dev/lp0
The printer code "\033\017" is an octal equivalent for condensed printing under an Epson-like dot matrix printers. Commonly, the following codes may also be used:
\033\115 for elite and \033\120 for pica
If you are using a different dot matrix printer, the printer codes are found in your printer manual.
Friday, December 19, 2008
Solution to PostgreSQL Serial Limitations
In PostgreSQL, an automatic incrementing column is called "serial". This is often used as a primary key of a table. The default serial column is of type INT4 which has a maximum value of 2,147,483,647. To increase this maximum number, create an INT8 data type for your serial column, as follows:
This will increase the capacity of the column to 9,223,372,036,854,775,807. I don't know if there is an INT16 column type. If there is, theoretically we can increase further the capacity of the column by a factor of 2 since PostgreSQL does not support unsigned integers as far as I know.
>CREATE SEQUENCE person_id_seq;
>CREATE TABLE person( id INT8 NOT NULL DEFAULT nextval('person_id_seq'), name TEXT);
>CREATE UNIQUE INDEX person_id_key on person(id);
This will increase the capacity of the column to 9,223,372,036,854,775,807. I don't know if there is an INT16 column type. If there is, theoretically we can increase further the capacity of the column by a factor of 2 since PostgreSQL does not support unsigned integers as far as I know.
Solution to MySQL auto_increment Limitations
By default, MySQL's auto_increment column has a maximum number of 2,147,483,647. In practice, this number may even be less since the next NULL insert to the table will use the next value of the highest insert number. Consequently, once you have reached the maximum number, the next null insert will cause an error because of the occurrence of a duplicate key.
The solution to MySQL's auto_increment limitations is to create a primary key as an UNSIGNED BIGINT(20) type. As an example for the table "mytest", issue the following MySQL command:
The UNSIGNED BIGINT(20) type has a maximum number of 18,446,744,073,709,551,616. A SIGNED BIGINT(20) type has a maximum number of 9,223,372,036,854,775,807. Since you will be using this as a non-duplicating primary key in your table, most likely you will be using the UNSIGNED BIGINT(20) type since there is no need for storing negative values.
The solution to MySQL's auto_increment limitations is to create a primary key as an UNSIGNED BIGINT(20) type. As an example for the table "mytest", issue the following MySQL command:
>CREATE TABLE mytest(p_id BIGINT(20) UNSIGNED PRIMARY KEY AUTO_INCREMENT, name CHAR(10) );
The UNSIGNED BIGINT(20) type has a maximum number of 18,446,744,073,709,551,616. A SIGNED BIGINT(20) type has a maximum number of 9,223,372,036,854,775,807. Since you will be using this as a non-duplicating primary key in your table, most likely you will be using the UNSIGNED BIGINT(20) type since there is no need for storing negative values.
Firewall Script
The following is a sample firewall script on Linux. It also acts as a network address translation (NAT) script that masquerades the IP addresses of the local area network. The script assumes that the local area network is in the 192.168.0.0 network class. Here it is:
# Load Modules
modprobe ip_conntrack
modprobe ip_conntrack_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
# Flush rules
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
# Default Deny Policy
iptables -P INPUT DENY
iptables -P OUTPUT DENY
iptables -P FORWARD DENY
# Perform NAT
iptables -t nat -A POSTROUTING -s 192.168.0.0/255.255.255.0 -d 0.0.0.0/0.0.0.0 -j MASQUERADE
Thursday, December 18, 2008
Removing Comment Lines and Spaces in a File
How to remove comment lines and spaces on a configuration file in Linux?
To remove comment lines under Linux, issue the following command:
Then, go can backup the original squid.conf file by copying it to say squidconf.bak:
And finally copying the new squid file to replace the original file as:
To remove comment lines under Linux, issue the following command:
# sed -e '/^#/d' -e '/^$/d' < squid.conf > newsquid.conf
Then, go can backup the original squid.conf file by copying it to say squidconf.bak:
# cp squid.conf squidconf.bak
And finally copying the new squid file to replace the original file as:
# cp newsquid.conf squid.conf
DHCP 3.x Server Configuration
The following is the DHCP 3.x configuration file "dhcpd.conf" on a Linux server:
-- Start of Configuration File --
-- Start of Configuration File --
-- End of Configuration File --
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.200;
option routers 192.168.0.254;
option subnet-mask 255.255.255.0;
option domain-name "portal.ph";
option domain-name-servers 192.168.0.1;
option netbios-name-servers 192.168.0.1;
default-lease-time 21600;
max-lease-time 43200;
}
Recovering Lost MySQL Password
The following are the steps on how to recover lost passwords in MySQL.
Steps:
1. Kill the MySQL daemon.
(the command on a RedHat-based system)
# /etc/rc.d/init.d/mysqld stop
2. Run the command:
# safe_mysqld --skip-grant-tables&
(on Fedora Core 5, the command is "mysqld_safe" instead of "safe_mysqld")
3. Go to the CLI.
#mysql
> use mysql
> update user set password=password('test123') where user='root' and host='localhost';
>\quit
4. Stop the MySQL
#mysqladmin -u root -p shutdown
5. Rerun MySQL
# /etc/rc.d/init.d/mysqld start
You can now access your database using the new password 'test123' as follows:
#mysql -u root -ptest123
Steps:
1. Kill the MySQL daemon.
(the command on a RedHat-based system)
# /etc/rc.d/init.d/mysqld stop
2. Run the command:
# safe_mysqld --skip-grant-tables&
(on Fedora Core 5, the command is "mysqld_safe" instead of "safe_mysqld")
3. Go to the CLI.
#mysql
> use mysql
> update user set password=password('test123') where user='root' and host='localhost';
>\quit
4. Stop the MySQL
#mysqladmin -u root -p shutdown
5. Rerun MySQL
# /etc/rc.d/init.d/mysqld start
You can now access your database using the new password 'test123' as follows:
#mysql -u root -ptest123
Subscribe to:
Posts (Atom)