Author Archive
Force SSL with mod_rewrite
by sudo on Oct.15, 2009, under Apache, Linux
Create a .htaccess within the document root with the following.
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
You must ensure AllowOverride is set to All within the apache configuration or it will not read the .htaccess.
Parse single table from mysqldump
by sudo on Oct.08, 2009, under Linux
If you wish to pull a single table from a large mysqldump, the following commands will accomplish this.
# grep -n "CREATE TABLE" databasedump.sql
If the table you want starts on line 100, and the proceeding table is on line 150, run the following commands to parse the dump.
# head -n 142 databasedump.sql > parsed.sql
# tail -n 100 parsed.sql > table.sql
Do not use the exact line number returned from grep as you will have the create table statement from the next table.
Remove Plesk Lockout
by sudo on Jul.28, 2009, under Plesk
Plesk will populate psa.lockout in mySQL in the event of the lockout. Either of the following will clear the lockout.
mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -e 'TRUNCATE lockout'
mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -e 'DELETE FROM lockout'
Check /usr/local/psa/admin/logs/httpsd_access_log for brute force attempts.
Display SAN information with powermt
by sudo on May.28, 2009, under Linux, Server
powermt display dev=all
This will display all information relevant to connected SAN devices.
# powermt
Usage:
powermt[class=all|clariion|ess|hitachi|hphsx|hpxp|invista|symm] powermt check [force] [hba=
|all] [dev= |all]
powermt check_registration
powermt config
powermt disable hba=
powermt display nonvirtual {dev=|all} [every=<#seconds>] [class=invista|all]
[width=<#col>]
powermt display [ports] [dev=|all] [every=<#seconds>]
[width=<#col>]
powermt display hba_mode
powermt display latency [dev=|all] [every=<#seconds>]
[width=<#col>]
powermt display options
powermt display paths [every=<#seconds>] [width=<#col>]
powermt display port_mode
powermt display unmanaged
powermt enable hba=
powermt load [file=]
powermt manage {dev=| class= }
powermt release
powermt remove [force] hba=|all | dev= |all
powermt restore [hba=|all] [dev= |all]
powermt save [file=]
powermt set mode=active|standby [hba=|all] [dev= |all]
powermt set path_latency_monitor=on|off
powermt set path_latency_threshold=
powermt set periodic_autorestore=on|off
powermt set policy={ad|bf|co|lb|li|nr|re|rr|so} [dev=|all]
powermt set port_disable={true|false} dev=
powermt set priority=[dev= |all]
powermt unmanage {dev=| class= }
powermt update lun_names
powermt version
Delete Sendmail Queue
by sudo on May.13, 2009, under Linux, Mail, Sendmail
When rm -rf /var/spool/mqueue gives you ‘bash: /bin/rm: Argument list too long’, you can use the following.
find /var/spool/mqueue/. -type f -exec rm -f {} ;
Total memory usage by Apache processes
by sudo on May.13, 2009, under Apache, Linux, Server
ps ax | grep httpd | awk '{ print $1 }' | xargs pmap -x | awk '{ SUM += $2 } END { print SUM }'
Fixing Urchin – Urchin: Unable to open database for writing since it has been archived
by sudo on May.04, 2009, under Linux
mkdir tmp; for i in `find ./*archive.zip`; do unzip $i; mv $i tmp; done; chown urchin:urchin *
Must be in the report directory for the profile.
/usr/local/urchin/data/reports/[profile name]
Backup mysql database to remote database
by sudo on Apr.09, 2009, under Linux
mysqldump --verbose --opt -u'username' -p'password' 'database' --tables 'table' | grep -v SQL_NOTES | mysql --host='hostname or IP' -u'username' -p'password' 'database'
Input all required information and remove the single quotations.
This specific command does a mySQL dump for a specific table within a database and pipes this output to a remote mySQL database connection.
The ‘grep -v’ was added to parse out SQL_NOTES as sending machine was 4.1.22 and receiver was 5.0.0 and did not like the syntax.
Display successful SSH brute force attempts from secure logs
by sudo on Apr.07, 2009, under Linux
for i in `grep "Failed password for invalid user" /var/log/secure | awk '{ print $13 }' | sort | uniq`; do grep $i /var/log/secure | grep "Accepted"; done
This is a work in progress.
Parses IPs from failed SSH attempts then runs it against the logs again for successful attempts.
Configure additional port for Qmail/ProFTPd
by sudo on Apr.07, 2009, under Linux
Add an entry in /etc/services for the specific port number you would like to listen on. Preferably copy the lines for 25/SMTP.
smtp 25/tcp mail
smtp 25/udp mail
smtp-alt 225/tcp mail
smtp-alt 225/udp mail
In the /etc/xinetd.d/ directory, copy smtp_psa to smtp2_psa. Open smtp2_psa and change the first line.
service smtp
to
service smtp-alt
Restart xinetd after complete and verify service is listening on the correct port.
– This can be applied to other services such as ProFTPd.