Wrap the PS AUX Output in Window
Typically to see all the services/commands running on a linux based machine you would use `ps aux` to get the output. What is frustrating is that it will not wrap the contents of each line. So if you have a small terminal or a process running with a lot of options then it will not display it completely.
Here are the last few lines of my ps aux. It will show that I’m running Chrome but I have no idea what options are set.
# ps aux david 4793 0.1 0.2 956644 43620 ? SNl 12:33 0:00 /opt/google/chrome/chrome --type=renderer --lang=en-US root 4819 0.0 0.0 0 0 ? S 12:38 0:00 [kworker/4:1] david 4829 0.6 0.4 992140 69688 ? SNl 12:40 0:02 /opt/google/chrome/chrome --type=renderer --lang=en-US david 4845 29.3 1.3 1125172 220924 ? Rl 12:41 1:16 /opt/google/chrome/chrome --type=renderer --lang=en-US root 4867 0.0 0.0 0 0 ? S 12:43 0:00 [kworker/4:2] david 4870 0.0 0.0 16584 2880 pts/1 Ss 12:45 0:00 bash david 4874 0.0 0.0 13128 1380 pts/1 R+ 12:45 0:00 ps aux
To make this work and receive the full output with wrapped lines:
# ps auxww david 4845 27.3 1.2 1117960 206944 ? Sl 12:41 2:14 /opt/google/chrome/chrome --type=renderer --lang=en-US --force-fieldtrials=ForceCompositingMode/disable/InfiniteCache/No/OmniboxHQPReplaceHUPProhibitTrumpingInlineableResult/Standard/OmniboxSearchSuggestTrialStarted2013Q1/15/OneClickSignIn/Standard/Prerender/PrerenderEnabled/PrerenderFromOmnibox/OmniboxPrerenderEnabled/SendFeedbackLinkLocation/control/SpdyCwnd/cwnd10/Test0PercentDefault/group_01/UMA-Dynamic-Binary-Uniformity-Trial/group_01/UMA-New-Install-Uniformity-Trial/Experiment/UMA-Session-Randomized-Uniformity-Trial-5-Percent/group_17/UMA-Uniformity-Trial-1-Percent/group_27/UMA-Uniformity-Trial-10-Percent/group_01/UMA-Uniformity-Trial-20-Percent/group_04/UMA-Uniformity-Trial-5-Percent/group_12/UMA-Uniformity-Trial-50-Percent/group_01/ --renderer-print-preview --disable-webgl --disable-pepper-3d --disable-gl-multisampling --disable-accelerated-compositing --disable-accelerated-2d-canvas --disable-accelerated-video-decode --channel=885.250.414971680 root 4867 0.0 0.0 0 0 ? S 12:43 0:00 [kworker/4:2] david 4870 0.0 0.0 16584 2880 pts/1 Ss 12:45 0:00 bash root 4888 0.1 0.0 0 0 ? S 12:48 0:00 [kworker/4:1] david 4896 2.0 0.3 982380 56792 ? SNl 12:48 0:01 /opt/google/chrome/chrome --type=renderer --lang=en-US --force-fieldtrials=ForceCompositingMode/disable/InfiniteCache/No/OmniboxHQPReplaceHUPProhibitTrumpingInlineableResult/Standard/OmniboxSearchSuggestTrialStarted2013Q1/15/OneClickSignIn/Standard/Prerender/PrerenderEnabled/PrerenderFromOmnibox/OmniboxPrerenderEnabled/SendFeedbackLinkLocation/control/SpdyCwnd/cwnd10/Test0PercentDefault/group_01/UMA-Dynamic-Binary-Uniformity-Trial/group_01/UMA-New-Install-Uniformity-Trial/Experiment/UMA-Session-Randomized-Uniformity-Trial-5-Percent/group_17/UMA-Uniformity-Trial-1-Percent/group_27/UMA-Uniformity-Trial-10-Percent/group_01/UMA-Uniformity-Trial-20-Percent/group_04/UMA-Uniformity-Trial-5-Percent/group_12/UMA-Uniformity-Trial-50-Percent/group_01/ --renderer-print-preview --disable-webgl --disable-pepper-3d --disable-gl-multisampling --disable-accelerated-compositing --disable-accelerated-2d-canvas --disable-accelerated-video-decode --channel=885.254.426002990 david 4904 0.0 0.0 13128 1380 pts/1 R+ 12:49 0:00 ps auxww
And there you go, I can see the full lines now which are wrapped to my window. Of course this is more helpful when seeing other services like MySQL or Varnish, but tis just an example my fried.
So in the future, use the command with ‘ww’ on the end.
# ps auxww
Service HTTPD Fullstatus Not Providing the Correct Information
I had an issue where when calling the following function, the typical status page with information about the Apache server was not coming up correctly.
When using one of the following commands, I was not receiving the status information.
# service httpd fullstatus # apachectl fullstatus
What was happening is that it was actually showing a text based version of the homepage instead of what I was expecting.
Low and behold the culprit was mod_rewrite. This particular site was a Drupal site using rewrites to get all fancy schmancy.
Here’s what the .htaccess file looked like.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Here’s what it looks like now:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
So as you can see, I added a rewrite condition to ignore server-status url. I can now see the correct fullstatus page as it is intended.
Bash Script: Mount Drive Automatically to Backup Using Rsync
Want a script that will automatically mount a spare hard drive and then sync a directory to it?
Really with this script you could set it up as a cronjob or you can manually run. You could even set this to be called before computer/server shutdown.
Basically what happens when I run this script is that it finds my hard drive by UUID and checks to see if it’s already mounted or not. If it’s not mounted it will mount the drive in the directory specified. After doing a few checks it will then use rsync to synchronize my /home directory. You could change this directory to anything really.
After the files are sync’d it will then decide if the drive needs to be unmounted or not.
Just set these variables at the top of the script.
UUID - Your hard drives UUID
BACKUPDIR - Where you want the files to be synced
TOBACKUP - What files you want synced
Pretty simple overall :)
#!/bin/bash
#backup harddrive variables
UUID='b8fa062f-a2be-41f2-ae02-0252620233b9'
BACKUPDIR='/run/media/david/1TBeast'
TOBACKUP='/home'
PARTITION=`/usr/bin/readlink -f /dev/disk/by-uuid/$UUID`
TIMER=3
#############################################################
echo 'UUID: ' $UUID
echo 'Drive Partition: ' $PARTITION;
#check drive and partiton match
if /sbin/blkid | grep -s "$PARTITION" | grep -q "$UUID"; then
echo 'Drive and partition match...'
else
exit
fi
#if [ -z "$DIRECTORY" ]; then
# echo 'No directory present...'
#fi
#check if drive mounted
if grep -qs $PARTITION /proc/mounts; then
#its already mounted
MOUNTED='1'
echo 'Drive already mounted...'
BACKUPDIR=`grep $PARTITION /proc/mounts | awk '{ print $2 }'`
echo 'Directory: ' $BACKUPDIR
else
#not mounted
MOUNTED='0'
echo 'Mounting drive...'
sudo mkdir -p "$BACKUPDIR"
sudo mount /dev/disk/by-uuid/$UUID "$BACKUPDIR"
echo 'Mounted: ' $BACKUPDIR
fi
#countdown before sync
printf "\nStarting Backup..."
until [ $TIMER = 0 ]; do
printf "$TIMER..."
TIMER=`expr $TIMER - 1`
sleep 1
done
echo ''
#perform home backup
sudo rsync -rave --stats --progress --delete $TOBACKUP $BACKUPDIR
#clean up
if [ $MOUNTED = 0 ]; then
#unmount and remove dir
echo 'Unmounting drive...'
sudo umount "$PARTITION"
sudo rmdir "$BACKUPDIR"
else
echo 'Leaving drive mounted...'
fi
echo 'Backup Complete!'
FrustratedTech - Server Admin Tool
This is a Google Chrome Extension.
Used to inspect the info about an IP or domain.
This tool is used for server administrators to quickly view information about a domains DNS information. It will display your IP address, the domains IP address, nameservers, A records, and MX records as well.
If you are in the web hosting profession or a server administrator of any kind, this app will help with quickly identifying what server a website is hosted on.
This tool also includes a quick blacklist scanner for the main A record the domain is pointing to. It will check the following blacklists to see if the IP is in fact listed:
bl.spamcop.net, cbl.abuseat.org, list.dsbl.org, b.barracudacentral.org, zen.spamhaus.org, dnsbl.sorbs.net
Furthermore, it will also provide quick access to the intoDNS and MX Toolbox services.
Server Timezone Correct, PHP Showing Incorrect Timezone Data
I came across and issue where the timezone of the server was already set to PST and was working just fine. However, setting the PHP date.timezone = “US/Pacific” was showing EST time instead of PST. Really odd.
Here’s what I did to fix the issue.
# yum reinstall tzdata
# date
# cp -p /usr/share/zoneinfo/US/Pacific /etc/localtime
# date
# service httpd restart
# php -r "echo date('l jS \of F Y h:i:s A');"
Block Facebook IP Ranges with CSF
I’ve seen issues with this recently where Facebook’s search bots will kill servers. They will create thousands of connections to servers and cause Apache, or whatever used, to go down due to OOM (Out of Memory).
I wrote a script that will query Facebook’s IP assignments and then send each range to CSF to get blocked. Here is the command line sequence you can use.
Block Facebook IP Range with CSF:
# for i in `whois -h whois.radb.net -- '-i origin AS32934' | grep '^route:' | awk '{print $2}'`; do csf -d $i; done
Unblock Facebook IP Range with CSF:
# for i in `whois -h whois.radb.net -- '-i origin AS32934' | grep '^route:' | awk '{print $2}'`; do csf -dr $i; done
For more information about CSF (ConfigServer Security & Firewall), please visit their website.
Apache Redirect HTTP to HTTPS
This is extremely easy…
Find your vhosts.conf or httpd.conf file. Wherever you have your VirtualHosts located for Apache.
Before the closing </VirtualHost> tag, add the below so that it will redirect.
This redirect can do anything, but we are using it for http to https so the visitors of the domain are forced to use an SSL connection.
Redirect permanent / https://domain.com/
jQuery Cycle plugin and IE Quirks Mode
This is so frustrating to me that I just had to post it somewhere.
When using the jQuery cycle plugin to rotate images (VERY SIMPLE) if your code that you are having to update is older HTML 4, then it is best to force the browser to emulate IE8 instead of Internet Explorer defaulting into Quirks Mode.
Add this to your <head> so that IE is told to default to IE8 and not screw everything up.
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
The reason I needed to add this was because the jQuery plugin was working perfect in all browsers and would work well with IE as long as it was using standard mode. But since IE doesn’t like to use standard mode for older websites, it defaults to quirks. This quirks mode causes the jQuery cycle plugin to not even display. The fix of course is to use the tag above.
PostgreSQL server: FATAL: no pg_hba.conf entry for host “::1”
Seeing this error?
Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: FATAL: no pg_hba.conf entry for host "::1", user "USERNAME", database "DATABASENAME", SSL off in /home/USERNAME/public_html/check.php on line 3
From what I understand it seems that Postgres is trying to connect through IPv6 and this is causing confusion. My personal fix for this is to add this entry to your pg_hba.conf file.
Edit: /var/lib/pgsql/data/pg_hba.conf
Added:
local all all md5
host all all ::1/128 re md5
After changing this then restart postgres and check your connection.
[Apache Startup Error]: apr_sockaddr_info_get() failed for
If you are seeing this error when starting Apache, then it is really simple to fix.
Starting httpd: apr_sockaddr_info_get() failed for domain.com
Just add the following line to your httpd.conf file and restart Apache.
ServerName localhost
Of course you can set this to your hostname for your server, but that’s not 100% necessary.
This issue occurs because Apache cannot determine the server’s fully qualified domain name. Manually setting the hostname is the fix for this issue.