Thursday, December 17, 2009

SED-Replace multiple lines with a single line

A useful option of sed command to replace multiple lines with a single line upon matching a given string.


$ cat -n file.txt
Hello world
Hello nobody
nobody
Somebody
anybody


If you want to replace the lines 2 and 3 with another line "Hello everybody" the below command will help.

$ sed '/nobody$/{N;s/Hello nobody\nnobody/Hello everybody/}' file.txt

$ cat -n file.txt
1 hello world
2 Hello everybody
3 Somebody
4 anybody

SMTP authentication through TELNET

It's common that we use TELNET to port 25 of Mail server to check the connectivity and to ensure the Mail flow.

It's also possible to perform SMTP authentication in TELNET session

$ telnet yourmailserver 25
type “HELO”, hit Enter.
AUTH LOGIN


Now you have to enter your email ID and then your password encoded in BASE64.
For converting your email and password to Base64 use the conversion tools at WebPan or Ostermiller

Reference
WebPan.com
KongTechnology

echo colourfully

# for i in `cat num.txt`; do echo -en '\E[3'$i'm'"\033[1mPsycho Tux\033[0m " ; done;
# for i in `cat num.txt`; do echo -en '\E[47;3'$i'm'"\033[1mPsycho Tux\033[0m " ; done;


# cat num.txt
1
2
3
4
5
6
7
8
9
0

Block direct SSH to root, but not to root equivalent

The PermitRootLogin no option of /etc/ssh/sshd_config will block all the users with UID 0. Below is an option to overcome this.

# vi /etc/ssh/sshd_config

###PermitRootLogin no
AllowUsers newuser guest psychotux hari
DenyUsers root

# /etc/init.d/sshd restart


Here users listed along with AllowUsers can be normal user or root equivalent.

Thursday, December 10, 2009

Hardware clock failure in ISA system

In ISA systems /sbin/hwclock will fail to fetch the Hardware clock and will throw an error similar to below.
# hwclock
select() to /dev/rtc to wait for clock tick timed out

# hwclock --show
select() to /dev/rtc to wait for clock tick timed out

But the --directisa option of hwclock will work here.
# /sbin/hwclock --directisa

So as a permanent solution we can rename the existing binary /sbin/hwclock and create a new Wrapper as below

1. Find the version of hwclock
# hwclock --version
2. Rename the binary by suffixing the version number
# cd /sbin
# mv hwclock hwclock-x.y
3. Create a wrapper for the hwclock-x.y named hwclock
# cat > hwclock << HERE
#!/bin/bash
/sbin/hwclock-x.y --directisa \$@
HERE

4. Give necessary execute permission and reboot the server
# chmod +x hwclock
5. Check the hardware clock, System Time, NTP, etc.
To synchronize system time with Hardware clock we can use hwclock --hctosys

And an optional reboot
# reboot

If your system is not ISA the we can try the RTC driver as well. The first thing we have to ensure is the RTC driver is loaded using the below steps.
# lsmod|grep rtc
This will show something like below
rtc 15329 0

If you are not getting any, then the rtc driver has not loaded. You need to load it

# modprobe rtc

AT&T USA | Internet not working | Fix by custom APN

If the AT&T Mobile internet is not working on your cellphone, it can be fixed easily by adding an APN configuration. You can read this a...