Generate lines in vi editor

When you need to add multiple similar records to a configuration file (IP addresses for example), you may use vi editor to do it directly:

[code] :r! for i in $(seq 1 5); do echo “This is line \#${i}”; done[/code]

This command wil generate 5 lines:
[code]
This is line #1
This is line #2
This is line #3
This is line #4
This is line #5
[/code]

Similar command used to generate Reverse DNS entries in BIND:

[code] :r! for i in $(seq 1 5); do echo “$i PTR host${i}.domain.com”; done[/code]
[code]
1 PTR host1.domain.com
2 PTR host2.domain.com
3 PTR host3.domain.com
4 PTR host4.domain.com
5 PTR host5.domain.com
[/code]

Line numbers can be changed, modifyng the $(seq 1 5); part.

Zabbix SNMP – Error building asn.1 representation

When installing Zabbix on Debian 6, you may enconter an error with SNMP checks.

Error building asn.1 representation

First try to retrieve the most basic uptime value with snmpget

[code]
snmpget -v2c -c public 123.45.67.89 SNMPv2-MIB::sysUpTime.0
Cannot find module (SNMPv2-MIB): At line 0 in (none)
[/code]

If you get similar output as above you are missing package snmp-mibs-downloader.

You can install this package via apt:

[code]
apt-get install snmp-mibs-downloader
[/code]

After installation restart zabbix-server

kernel: e1000e eth0: Error reading PHY register

In recent CentOS version 6.3 is an unresolved bug, which causes the network card to freeze the server.

Following message appears in /var/log/messages

[code]
kernel: e1000e 0000:02:00.0: eth0: Error reading PHY register
[/code]

To work around the problem you will need to turn off Active-State Power Management (ASPM)
(Feature that saves power in the Peripheral Component Interconnect Express (PCI Express or PCIe) subsystem by setting a lower power state for PCIe links when the devices to which they connect are not in use)

For GRUB bootloader edit the following file: /boot/grub/grub.conf and append pcie_aspm=off to the end of kernel boot line.

For example:
[code]
kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=UUID=81e9e0a2-0a51-4d75-955d-909aaf848192 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_DM rd_MD_UUID=c6855f45:016a63bb:2d79bfb2:07371ed8 rd_NO_LVM rd_MD_UUID=5d5a434e:6c20cfcd:51340c3f:29c29151 pcie_aspm=off
[/code]

To verify the change, reboot the server and run the following command:

[code]
dmesg | grep PCIe
PCIe ASPM is disabled
[/code]

If your output is different, the change in grub.conf did not take an effect.

Add / substract time in bash

To add or substract any amount of seconds, minutes, hours, days, weeks, months or years to/from current date use the Linux date command:

[code]
date -d ‘+2 hour’
[/code]

If you want to use specific date as a base:

[code]
date -d ‘2010-01-01 + 2 year’
[/code]

Oracle 11 Install without X

For Oracle 11g2 installation on a server, that has no X11 available you will have to use specific argument for install command:

[code]
runInstaller -silent -responsefile db.rsp
[/code]

db.rsp is an Oracle response file for providing required values for installation, that would be otherwise asked by graphical installer.
NB! Relative path to response file is not supported (like ../../db.rsp).

Here is an example of a response file for Oracle 11g2

[code]
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=localhost
UNIX_GROUP_NAME=oracle
INVENTORY_LOCATION=/opt/oracle/oraInventory
SELECTED_LANGUAGES=en
ORACLE_HOME=/opt/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/opt/oracle

oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=false
oracle.install.db.optionalComponents=
oracle.install.db.DBA_GROUP=oracle
oracle.install.db.OPER_GROUP=oracle

oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=false
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=
oracle.install.db.config.starterdb.SID=
oracle.install.db.config.starterdb.characterSet=
oracle.install.db.config.starterdb.memoryOption=false
oracle.install.db.config.starterdb.memoryLimit=
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
oracle.install.db.config.starterdb.storageType=
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
MYORACLESUPPORT_USERNAME=
MYORACLESUPPORT_PASSWORD=
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=SKIP_UPDATES
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES_MYORACLESUPPORT_USERNAME=
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=

[/code]

Or download this response here: Oracle 11 Answer file

Using this response file you will install Oracle Enterprise edition without creating a database to /opt/oracle using user “oracle” and group “oracle“. You may change user, group and install folder by editing the response file.

NB!
Before running the installer ensure you have created user oracle and added permissions for /opt/oracle folder. Also install Oracle prerequisite packages by running:

[code]
yum install gcc gcc-c++ gcc-c++-devel glibc-devel libgcc libgcc-devel libaio libaio-devel compat-libstdc++-33 libstdc++ libstdc++-devel elfutils-libelf-devel ksh
[/code]