Author Archives: Randy

Bash: How to add a line on top of text files with sed

Sometimes you might need to add one or more lines of text to the top of an existing text file. Let ‘sed’ rescue you: sed -i ‘1iSTUFF TO ADD’ file.txt You can add multiple lines (separated by \n) to multiple files at once: sed -i ‘1iSTUFF TO ADD\nMORE STUFF’ *.txt

Categories: Code, Linux, and Technical. Comments Off on Bash: How to add a line on top of text files with sed

Find files modified/created within N days ago

This proved to be useful in cleaning up a compromised site. List all the files created or modified within a certain time frame — in this case we are looking 30 days in the past: find . -mtime -30 -type f -print If you want to delete all files created/modified n days ago, you can […]

Sorting disk usage by folder in Linux

Normally you would use something like this: du -k | sort -nr > sorted.txt But the output is not pretty since we don’t like counting bytes. This will sort it in human readable format: du -k | sort -nr | awk ‘ BEGIN { split(“KB,MB,GB,TB”, Units, “,”); } { u = 1; while ($1 >= […]

Categories: Uncategorized. Comments Off on Sorting disk usage by folder in Linux

Pre-analysis of a DDOS attack on a Cpanel or Linux server

Determine the nature of the attack (SYN, GET, ect): netstat -nat | awk ‘{print $6}’ | sort | uniq -c The following will list all the IPs connecting to the server in order of most connections. netstat -plan|grep :80|awk {‘print $5’}|cut -d: -f 1|sort|uniq -c|sort -nk 1 We can see which domains are most active […]

Tracking SPAM on a Cpanel Server

If you are using a cpanel/WHM server then the MTA will be Exim by default. Enable Mailheaders by running /scripts/easyapache script.  After that, check the mail header using: exim -Mvh <message id> From that you will able to find the source of spam.

Categories: Linux and Technical. Comments Off on Tracking SPAM on a Cpanel Server

Setting up Adaptec Storage Manager on a headless Ubuntu/Debian server

Adaptec RAID cards have huge performance gains over other cards, but the management features in Linux stink. Really bad. If you don’t have a GUI installed, you cannot set up monitoring or alerts, but thankfully you can use a Windows machine to set this up remotely. Additionally, there are no .deb packages so we have […]

Installing mod_limitipconn on a Cpanel server

Absolutely essential in a shared hosting environment. This example is relevant to Apache 2.2.x. ############# ## Compile mod_ipconnlimit cd /root wget http://dominia.org/djao/limit/mod_limitipconn-0.23.tar.bz2 tar xjf mod_limitipconn-0.23.tar.bz2 cd mod_limitipconn-0.23 /usr/local/apache/bin/apxs -cia mod_limitipconn.c ### this needs to be redone after each apache recompile ## in WHM, add to apache Pre VirtualHost Include (all versions) <IfModule mod_limitipconn.c> # Set […]