Vi delete commands – reference

A lot of times all people need is a quick reference, so I’ll start with a reference of vi/vim delete commands:

x – delete current character
dw – delete current word
dd – delete current line
5dd – delete five lines

d$ – delete to end of line
d0 – delete to beginning of line

:1,.d
delete to beginning of file

:.,$d
delete to end of file

Block an IP address with null routes or with iptables on a Linux.

You can drop as IP address using the iptables command:

iptables -A INPUT -s 192.168.1.100 -j DROP
iptables -A OUTPUT -d 192.168.1.100 -j DROP

However, you can use route or ip command to a null route unwanted traffic. A null route is a network route or kernel routing table entry that goes nowhere.

route add 192.168.1.100 gw 127.0.0.1 lo

or reject 😉

route add -host 192.168.1.100 reject

Also we can drop entire subnet 192.168.1.0/24

route add -net 192.168.1.0/24 gw 127.0.0.1 lo

To delete an IP address or entire subnet from a null route use the following command:

route del 192.168.1.100 gw 127.0.0.1 lo

or

route del -net 192.168.1.0/24 gw 127.0.0.1 lo

or

route del -host 192.168.1.99 reject

The df command not showing correct values.

A common programming technique is to create a temporary file and immediately unlink() it. This leaves the file (and its space) available for the duration of the program but automatically causes its removal when the program using it terminates. One advantage is that no epilog (cleanup) code is necessary to write. To determine if you have a process holding an unlinked file open, do:

lsof -a +L1 /ebstest01db

or

lsof +D /ebstest01db +L1

Look for any files with an NLINK value of zero (0). These would be files with a zero link count that will vanish when the last process terminates. The SIZE/OFFSET column will offer the character size of the file in question.

sles02:/ # lsof -a +L1 /ebstest01db
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
oracle 9605 ebstest01 256u REG 8,33 40255488 0 3678213 /oradata/data_old/cntrl01.dbf (deleted)
oracle 9605 ebstest01 257u REG 8,33 40255488 0 5775361 /oradata/data_old/cntrl02.dbf (deleted)
oracle 9605 ebstest01 258u REG 8,33 40255488 0 9969665 /oradata/data_old/cntrl03.dbf (deleted)
oracle 9605 ebstest01 259uW REG 8,33 4294975488 0 2629640 /oradata/data_old/system01.dbf (deleted)
oracle 9605 ebstest01 260uW REG 8,33 4294975488 0 3678209 /oradata/data_old/system02.dbf (deleted)
oracle 9605 ebstest01 261uW REG 8,33 4294975488 0 3678210 /oradata/data_old/system03.dbf (deleted)
oracle 9605 ebstest01 262uW REG 8,33 4294975488 0 1597441 /oradata/data_old/system04.dbf (deleted)
oracle 9605 ebstest01 263uW REG 8,33 4294975488 0 1597448 /oradata/data_old/system05.dbf (deleted)
oracle 9605 ebstest01 264uW REG 8,33 4294975488 0 1597449 /oradata/data_old/system06.dbf (deleted)
oracle 9605 ebstest01 265uW REG 8,33 4294975488 0 1597450 /oradata/data_old/system07.dbf (deleted)
oracle 9605 ebstest01 266uW REG 8,33 4294975488 0 1597451 /oradata/data_old/system08.dbf (deleted)
oracle 9605 ebstest01 267uW REG 8,33 4632879104 0 4931624 /oradata/data_old/sysaux01.dbf (deleted)
oracle 9605 ebstest01 268uW REG 8,33 4554235904 0 4931599 /oradata/data_old/sysaux02.dbf (deleted)

And now kill the 3605 process.

Lists all files beginning with n or S followed by "-release".

ls [nS]*-release

Lists all files beginning with n or S followed by “-release” (e.g., novell-release)

oes11-34:/etc # ls -la [nS]*-release
-rw-r--r-- 1 root root 72 Jan 21 2014 novell-release
-rw-r--r-- 1 root root 69 Jun 3 2013 SuSE-release
oes11-34:/etc # cat [nS]*-release
Novell Open Enterprise Server 11 (x86_64)
VERSION = 11.2
PATCHLEVEL = 2
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 3
oes11-34:/etc #

Set a directory quota on an OES11 – NSS volume using a command line.

Disk Quotas is the most natural starting point in building a solid storage strategy. Setting quotas will easily let you:
– Show users what reasonable storage use is – define an upper limit.
– Allow storage to grow in a controlled and sustainable manner.
– Promote efficient usage and streamline backup/restore times.

This script will set a quota directory on the Novell Storage Services for Novell Open Enterprise Server 11.
Continue reading “Set a directory quota on an OES11 – NSS volume using a command line.”

Restart an iPrint services.

novell-ipsmd lets you to start and stop the ipsmd daemon that manages printers that are assigned under a Print Manager.
novell-idsd lets you to start and stop the idsd daemon that manages drivers that are assigned under a Driver Store.

To restart an iPrint services just type:

nbip1:~ # rcnovell-idsd restart && rcnovell-ipsmd restart
Shutting down Novell iPrint DriverStore. done
Starting Novell iPrint DriverStore: done
Shutting down Novell iPrint Manager.. done
Starting Novell iPrint Manager: done
nbip1:~ #

Use logger to write a messages to log files.

The basic syntax for logger is logger message. It does not require any options if you are just going to write a message to the logfile and you want to write to the default /var/log/messages at the notice level.

root# logger Added a new disk to a machine

You can see a message in /var/log/message file. Also you can run this command with option -s Log the message to standard error, as well as the system log.

root# logger -s Added a new disk to a machine

Port forwarding using xinetd.

An easy method to do port forwarding without the iptables is to use the xinetd.
In order to port forward with xinetd, you will need to create a configuration file:

root# vim /etc/xinetd.d/imap_forward

For example: Forward port 143 on localhost to remote server on port 143:

service imap_forward
{
disable = no
type = UNLISTED
socket_type = stream
protocol = tcp
user = nobody
wait = no
redirect = remote_IP_or_server_name 143
port = 143
}