Category: Terminal/Shell

Backups

Remote backup of user directory and MySQL database that deletes the backup from 4 weeks ago serverLocation=”example.com”; syncLocation=”/media/StorageDrive/example.com.sync/”; saveLocation=”/media/StorageDrive/example.com.backups/”; rsync -a root@$serverLocation:/home/ $syncLocation/home/; ssh root@$serverLocation -t “mysqldump –all-databases” > $syncLocation/mysql.sql; cd $syncLocation; tar -cvzf $saveLocation/$(date +%y-%m-%d).tar . ; rm -f /home/user123/mail-backup-$(date –date=”4 weeks ago” +%y-%m-%d).tar; Local cron backup command for one email account that deletes…
Read more

Nginx Commands

Check for nginx netstat -lntp | grep nginx Check that apache is not using the same ports netstat -lntp | grep httpd Clear nginx cache ngxconf -u userna5 -rd Rebuid rules You must run this after you change the any nginx config files. This will tell you if there are bad rules. nginx -s reload…
Read more

Backups

To check for backups, replace userna5 with the database name ls -la /bkmnt/var/lib/mysql | grep userna5 Replace userna5_db with the database name restore-db userna5_db Check the latest backup for a user ls -la /opt/backup/logs/users/userna5 or cat /opt/backup/logs/users/userna5

Create php.ini File

Create a php.ini file from the currently loaded one. Make sure you replace ‘http://example.com/’ with the public path of the current directory. cp $(echo “<?php phpinfo(); ?>” > phpinfo.php; wget http://example.com/phpinfo.php -O – | sed ‘s#<head>[^<]*</head>##g’ | sed ‘s#<footer>[^<]*</footer>##g’ | sed ‘s#<script>[^<]*</script>##g’ | sed ‘s#<style>[^<]*</style>##g’ | sed ‘s/<[^>]\+>//g’ | grep -v ‘^$’ | grep “Loaded…
Read more

List/Delete Files by date

List files modified before date (use -newerBt for created date) find . -type f ! -newermt 2016-12-31 | tail Delete files modified before date (use -newerBt for created date) find . ! -newermt 2013-12-31 -type f -delete

Find Email Sources

Find email from a cpanel user echo -n “List top email senders for which cp user: “; read user; sudo cat /var/log/exim_mainlog| LC_ALL=C grep -E “

Find Bad Mail Login Attempts

Find the number of failed logins per IP address in the maillog sudo tail -100000 /var/log/maillog | grep “auth failed” | cut -c 60- | awk -F”[ =,]” ‘{count[$16] += $4}END{for(i in count)print count[i] ” – ” i}’ | sort -rn | head -15 find bad login attempts and catalog the main target emails for…
Read more

Find A, NS, and MX Records for a List of Domains

Change “domains.txt” to your file. cat domains.txt | while read in; do echo “”; echo “$in”; echo “—————“; dig -t ns “$in” @ns +short; dig -t mx “$in” @ns +short; dig -t soa “$in” @ns +short; done

Server Sync Script

This script is a work in progress to sync my VPS. Right now the only things I utilize are the cPanel based apache server and the MySQL server. If you run other things, you will have to add to this. You will need to answer password prompts if you have not set up keys. server=”example.com”…
Read more

RHEL/CentOS/Fedora Fix-all packages

I used this to get out of a real tough situation. My home server was crashing due to a hardware problem and of coarse it crash during updates. At first this happened every once in a while and yum-complete-transaction would bring it back. But one day it crashed hard. I had to boot into my…
Read more