Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Sasha http://nothing-less.net

« Newer Snippets
Older Snippets »
Showing 1-10 of 20 total  RSS 

Compress file in SSH

The below will compress a file or folder in .tar.gz format in SSH.

tar -zcvf <new_tar_filename>.tar.gz <filename/directory>

Migrate a site to another server

Use the code below in SSH to migrate all the files of a site from one server to another, without having to download/upload them.

wget -rc --level=20 ftp://username:password@olddomain.net/public_html

Migrate a MySQL Database to another server

Use the below in SSH to move a MySQL database between servers. Super handy if the database is larger than 7MB and you can't use phpMyAdmin.

mysqldump -h oldhost -u oldusername -poldpassword olddbname | mysql -h newhost -u newusername -pnewpassword newdbname     


http://wiki.dreamhost.com/index.php/Migrate_MySQL

Search for terms in Domlogs

How to search for certain terms in your Domlogs, using SSH.

for files in /usr/local/apache/domlogs/*; do grep "wget" $files; done;


-OR-

cd /usr/local/apache/domlogs
grep wget *
grep lynx *
grep curl *


Replace wget with other file names/terms you might want to search for.

If that takes too long, try doing it one by one:

grep wget a*
grep wget b*
grep wget c*
grep wget d*
grep wget e*
grep wget f*
grep wget g*
grep wget h*
grep wget i*
grep wget j*
grep wget k*
grep wget l*
grep wget m*
grep wget n*
grep wget o*
grep wget p*
grep wget q*
grep wget r*
grep wget s*
grep wget t*
grep wget v*
grep wget w*
grep wget x*
grep wget y*
grep wget z*


Alternatively, if you get an error like "Argument list too long":

for i in `ls /usr/local/apache/domlogs|grep -v 'bytes_log'`; do echo "checking on $i" && grep wget /usr/local/apache/domlogs/$i && grep lynx /usr/local/apache/domlogs/$i && grep curl /usr/local/apache/domlogs/$i; done > /root/grep-domlogs-results.txt

Then simply take a look at this file /root/grep-domlogs-results.txt

Looking up recent dictionary attacks

Use the code below to look up what words were used in recent dictionary attacks using SSH.

grep "dictionary attack" /var/log/exim_mainlog

Looking into DOS and DDOS Attacks

A good guide to what to do when your server is attacked.

top -d2
netstat -nap | grep SYN | wc -l
netstat -nap | less


If there are many httpd processes showing up after step 1, you might be under attack. If you get high numbers for the second one, you are almost definitely under attack. Use the third one to see the IP addresses, and then ban them from the server:

iptables -A INPUT -s ip.address -j DROP


Also try the following for fixing stuff:
cd /dev/shm
ls


And delete anything that's not supposed to be there.

locate bindz
locate botnet.txt
locate dc
locate ex0.pl
locate kaiten
locate r0nin
locate udp.pl
locate ...
lsof | grep .,
locate mybot

Ban IPs from a server

Use the code below to permanently ban an IP address from accessing your server.

iptables -A INPUT -s ip.address -j DROP

How to tail logs

tail -200 /var/log/exim_mainlog
tail -200 /usr/local/apache/logs/error_log


To watch the log get updated in real time:

tail -f /var/log/messages 

Sims 2 File Limit Fix

Type this into Terminal in Mac OSX to fix the file size limit for The Sims 2, allowing you to have more than 5000 downloads.

sudo sysctl -w kern.maxfiles=22000
sudo sysctl -w kern.maxfilesperproc=20000

How To Manually Update Cpanel

/scripts/upcp

/scripts/upcp --force
« Newer Snippets
Older Snippets »
Showing 1-10 of 20 total  RSS