Posts

Replace string on a folder recursively via grep and sed

This is the script I created to replace a string on folders recursively Many thanks to serverfault users and othe person that helped me create this script #!/bin/bash # user input echo "Enter string to be replaced" read OLDSTRING echo "Enter string to be placed" read NEWSTRING echo "===================================" echo "string to be replaced is $OLDSTRING" echo "string to be placed is $NEWSTRING  " echo "===================================" oldstr=$OLDSTRING #string to be replaced newstr=$NEWSTRING #new string to be placed echo "Enter folder path where we will find the string" read FOLDERPATH ### grep oldstring and output it in grep_output.txt    STEP1 grep -rl $oldstr $FOLDERPATH > grep_output.txt ### since there might be spaces or special characters on filenames, use sed to enclose them with quote and output in  sed_output.txt  STEP2 #for i in `cat grep_output.txt` #do sed -e "s/'/'\\\\...

How to block an IP using iptables

iptables -A INPUT -s xx.xx.xx.xx -j DROP specific port:   iptables -A INPUT -p tcp -s xx.xx.xx.xx --dport PORT -j DROP allow access to an IP?   iptables -A INPUT -s xx.xx.xx.xx -j ACCEPT allow access to an IP to a specific port using iptables?   iptables -A INPUT -p tcp -s xx.xx.xx.xx --dport PORT -j ACCEPT where, xx.xx.xx.xx is the remote IP address and PORT is the port number you wish to allow/deny access to. block a scanner on your server for example “w00tw00t.at.ISC.SANS” using iptables? iptables -I INPUT -p tcp --dport 80 -m string --algo bm \ --string 'GET /w00tw00t.at.ISC.SANS.' -j DROP   Source: http://safesrv.net/quick-how-to-denyallow-ip-using-iptables/

Checking Apache for possible hack

1. Edit php.ini sendmail_path = /usr/local/bin/phpsendmail create a filter file wrapper. I saw this one and it is very handy. /usr/local/bin/phpsendmail #!/usr/bin/php <?php /**   This script is a sendmail wrapper for php to log calls of the php mail() function.   Author: Till Brehm, www.ispconfig.org   (Hopefully) secured by David Goodwin <david @ _palepurple_.co.uk> */ $sendmail_bin = '/usr/sbin/sendmail'; $logfile = '/var/log/mail.form'; //* Get the email content $logline = ''; $pointer = fopen('php://stdin', 'r'); while ($line = fgets($pointer)) {         if(preg_match('/^to:/i', $line) || preg_match('/^from:/i', $line)) {                 $logline .= trim($line).' ';         }     $mail .= $line; } //* compose the sendmail command $command = 'echo ' . escapeshellarg($ma...

Firebird create and restore backup

Create Database on FireBirdie [root@data]# /usr/lib64/firebird/bin-superserver/isql Use CONNECT or CREATE DATABASE to specify a database SQL> create database 'mydatabase.gdb' CON> user 'sysdba' password 'masterkey'; SQL> quit; Dump the old backup [root@data]# gbak -r o -v -user SYSDBA -password masterkey /home/dbackup/mydatabase-2013-06-20.gbk mydatabase.gdb

Socket file /var/run/clamav/clamd.sock could not be bound: Permission denied

I have been having this problem on some installations of amavis and clamav using Centos and Ubuntu. I might have passed a step on installation. The problem is permission in exact and I have been editing groups and users amavis, clamav and root A solution was posted on http://www.howtoforge.com/forums/showthread.php?t=34559 might do the trick. For a quick fix (not a good one) chmod 777 the folder =)

Linux Postfix single data server with master slave replication for courier-imap authentication

Image

tmfs increase size

edit /etc/fstab line to look something like this: tmpfs                   /dev/shm                tmpfs   size=10g        0 0 remount it mount -o remount tmpfs