Archive
Bash search and replace ip script
You can search and replace and IP address in bind (named.conf) or name server records with this script:
Assign values as indicated.
#!/bin/bash
x=`cat oldip`
a=`cat newip`
cmd=”sed -e”
$cmd “s#$x#$a#g” oldconfigfie > new.configfile
Handy script to parse Postfix maillogs for failed login IP addresses
You can use the script below to parse your maillog (mail.log on Debian based distros) for failed login attempts and place the results in your hosts.deny file or your IP tables config. The script deletes leading 0 IP addresses and filters out [brackets]. You can change the grep filter phrase to your liking.
grep “failed” /var/log/maillog | grep -Eo “([0-9]{1,3}.){3}[0-9]{1,3}” | sed ‘s/^[0]*//’ | uniq
could not load /lib/modules/2.6.35-22-server/modules.dep …
and change MODULES=most to MODULES=dep
procmail (with postfix) Could’nt create “/var/mail/nobody”
If your using procmail with Postfix you may get this error. You can correct it this way.
Procmail requires a legitimate user to receive mail. User “nobody” is not a legitimate user. In order to have
this work you must either run procmail as root or setuid root. To have procmail run a setuid root, chmod
4755 /usr/bin/procmail.
procmail (with postfix) Could'nt create "/var/mail/nobody"
If your using procmail with Postfix you may get this error. You can correct it this way.
Procmail requires a legitimate user to receive mail. User “nobody” is not a legitimate user. In order to have
this work you must either run procmail as root or setuid root. To have procmail run a setuid root, chmod
4755 /usr/bin/procmail.
fix dovecot error dovecot:Failed:listen (0.0.0.0,995) failed Address already in use
You can find conflicting ports with the lsof command. Use lsof -i :143 for instance to find what
is using imap port 143. If you find a conflict, then you just have to eliminate the conflict.
This error was caused on my system by the presence of the rpc.stated daemon. To disable
simply run chkconfig nfslock off and restart your system. Strangely, when I dovecot started
normally, you could then start the rpc.stated daemon without conflict. I left it disabled however
as I didn’t need it on that system.
Another handy utility for a Centos system is ntsysv. This gives you a gui view of daemons on
your system and the ability to turn them on or off.
resize xen image
To resize a xen image, follow these steps.
First make a backup copy of the image, ie cp xen.image, xen.image.backup then
dd if=/dev/zero of=[image_name] bs=1 count=1 seek=20G conv=notrunc
where seek=[size in GB]
then, e2fsck -f [image_name}-y
and finally
resize2fs -p [image_name]
You should then be able to boot the new image with the new size.
Edit dns records with sed or vi (search and replace)
You can easily replace an existing IP with and new IP in a dns record using sed. Here is the way
you do it.
sed -e ’s#xx.xx.xx.xx#yy.yy.yy.yy#g’ domain.com > new.domain.com
where xx.xx.xx.xx is the existing IP and yy.yy.yy.yy is the new IP
Using vi is similar. Here is the syntax:
vi yourzone.com . For instance, to change IP addresses:
<ESC>
:%s/xxx.xxx.xxx.xxx/yyy.yyy.yyy.yyy/g (where xxx is original IP and yyy is new IP)
<ESC> ZZ (to save file)