Archive for Linux

Gogrid – service going down hill – 10000% uptime guaranteed – false advertising

There was a time I recommended gogrid to many people – having moved away from uk2.net which was just about as dreadful as it gets as far as maintaining a service goes.

Twice this week now go-grid (www.gogrid.com) have had network problems. They have a 10000% guaranteed uptime yet in about 7 months I’ve had in access of 7 hours outage and yet to receive any form of reimbursement.

Basically, if you have mission critical appliances then you can’t rely on go-grid either.

The RFO’s from the last outage tells us the blame is due to DOS against another of their servers and they said it would be fixed. The truth is, they fixed nothing and AGAIN my server can’t be accessed.

I supposed the next step is to move business to Amazon EC2.. More to do…
13   183 ms   178 ms   179 ms  ae-92-92.ebr2.SanJose1.Level3.net [4.69.134.221]

14   180 ms   180 ms   179 ms  ae-1-6.bar2.SanFrancisco1.Level3.net [4.69.140.1
3]
15   180 ms   180 ms   219 ms  ae-4-4.car2.SanFrancisco1.Level3.net [4.69.133.1
7]
16   180 ms   179 ms   180 ms  SERVEPATH.car2.SanFrancisco1.Level3.net [4.53.13
.18]
17     *        *        *     Request timed out.
18     *        *        *     Request timed out.
19     *        *        *     Request timed out.
20     *        *        *     Request timed out.
21     *        *        *     Request timed out.
22     *        *        *     Request timed out.
23     *        *        *     Request timed out.
24     *        *        *     Request timed out.
25     *        *        *     Request timed out.
26     *        *        *     Request timed out.
27     *        *        *     Request timed out.
28     *        *        *     Request timed out.
29     *        *        *     Request timed out.
30     *        *        *     Request timed out.

race complete.

:\wamp\bin\apache\apache2.2.8\bin>

Comments (3)

bit of bash script to remove files from a dir when they are 30 minutes old

Problem

(paraphrased/untested) : – find . -type f -mtime xx -exec rm {}\;
doesn’t always have a high enough resolution when you want to remove a file
that is seconds or minutes old.

In my application, I have “guest writers” who preview their web content
before submitting for review. I don’t want web robots to index this content
(so will have a meta in the html to that effect anyway) and I don’t want
nosy readers of my sites to be familiar with tmp files which are under the
wwwroot so they can read stuff that has yet to be approved AND also I want to
do good housekeeping and remove tmp content fairly quickly.
I could use a “staging” web server, after they author presses the
preview button, a temp web page is rendered. I can delete this page within
seconds of it being viewed – this is fine.

Solution

The following code will be run in cron, maybe every half an hour

Where

time resolution is in seconds thus the division by 60 to get minutes
bash does not do natively division hence the pipe to bc
the file is the modify time

#!/bin/bash
#  echo  " (`date +%s` -  `stat -c %Z 12345`) / 60"   | bc -l

for i in `ls -b $FILEPATH`;
do

   U=$(( (`date +%s` - `stat -c %Z $i`) / 60 | bc -l ))

   if [ $U -gt 30 ]; then
     echo "$i is too old - will delete $U"
#    insert the DANGEROUS bit here
   else
     echo "too young - will not delete $U";
#    no dangerous bit here
   fi

done

Leave a Comment

InnoDB MyISAM mysqlhotcopy import bug table not found

If table not found errors occur on target db after transferring database 
then do the following:
1. check permissions on the folders and files under
/var/lib/mysql (esp if you copied as root).

Files should be mysql:mysql, as a rule.

2. On the source db, 

mysql> select table_name,table_type,engine from
information_schema.tables
where engine='InnoDB';

+--------------+------------+--------+

| table_name   | table_type | engine |

+--------------+------------+--------+

| crypto       | BASE TABLE | InnoDB |

+--------------+------------+--------+

x rows in set (5.80 sec)

The convert the db to ISAM

mysql> alter table crypto engine=MyISAM;

Query OK, 0 rows affected (0.12 sec)

Records: 0  Duplicates: 0  Warnings: 0

Leave a Comment

List folders and not sub files/folder of folders in Linux

http://www.cyberciti.biz/faq/linux-list-just-directories-or-directory-names/

Well done again cyberciti. Excellent solution

As it says on the link, add these to ~/.bash_profile

alias lf="ls -l | egrep -v '^d'"
alias ldir="ls -l | egrep '^d'"

Then (article aught to remind you of this) bring it to life with .  ~/.bash_profile

Leave a Comment

SSL Checklist Apache2 Centos5 HideMyIP

Installing an SSL certificate on Apache2 on Centos5

If you have not generated a certificate then suggest you jump to that section first then scroll back up.

Checks to be made in

/etc/httpd/conf.d/ssl.conf
under <VirtualHost _default_:443>

1. ServerName www.<mysite.com>:443

(Failure to set this will result in SSL_ERROR_RX_RECORD_TOO_LONG or “unsupported proxy” by Firefox)

2. In ssl.conf: SSLCertificateFile  <path to> /www.<mysite.com>.crt
This is the file sent by the SSL certificate provider.

3. In ssl.conf: Ensure SSLCertificateKeyFile is set to valid path to key

4. In ssl.conf: SSLCertificateChainFile  <path to> gd_intermediate_bundle.crt
The bundle file comes with the certificate (at least with DoDaddy).

5. Check iptables, port 443 should be enabled.

6. Check ssl is installed (yum list | grep ssl)

7. Check router port forwarding is enabled for port 443.

8. If you are testing a web server on the same net as the machine there is a chance the router is resolving the external facing ISP issued IP in such a way that it is impossible to test a your own website from the internet. intranet.  Some routers don’t permit it at all, e.g. netgear DG814 with recent firmware v 4.10 or below.

The fix is to use a proxy server like www.turbohide.com for testing or even install (read warning before buying) HideMyIP from www.hide-my-ip.com to fake the ip of the machine used to test.  You get a 3 day trial or buy for £16 ish. Warning: HideMyIp will reduce your bandwidth very noticeably unless you upgrade to the premium service this is probably because of the proxies used as the free ones suffer also – though there are other products – I’ve not tried them.

9. Restart web server

# /usr/sbin/apachectl graceful
httpd not running, trying to start
Apache/2.2.3 mod_ssl/2.2.3 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.

Server www.<my site>.com:443 (RSA)
Enter pass phrase:

OK: Pass Phrase Dialog successful.

If you don’t get the above information the first time when you start then your cert is not installed properly.

10. Protect your pages. For example (and there are many on the net)

if ($_SERVER['SERVER_PORT'] != 443)
{
header(“Location: https://www.mysite.com/”); // ssl site now
exit;
}

and/or setup a location rewrite in ssl.conf:

<Location /mywebfolder>
RewriteEngine on
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^.*/mywebfolder(.*)$ https://%{SERVER_NAME}:443/mywebfolder$1 [R]
</Location>

or .htaccess in the web folder – here we are challenged for a password and its said where the .htpasswd file is:



AuthUserFile /var/www/html/.htpasswd
AuthName "Secret stuff going on here - you need a password"
AuthType Basic
Require valid-user
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

Any of this not working then check the error_log (in /etc/httpd/logs). Not forgetting to apachectl graceful and clear the browser session info between tests (for the password challenge bit).

Generate Certificate

Execute this:

openssl genrsa -des3 -out www.<my site.com>.key 1024

Use the outfile and execute this:

openssl req -new -key www.<my site.com>.key -out <my site.com>.csr

The resulting file is <my site.com>.csr

`cat` the file to copy the content and past it into the browser with prompted by the ssl issuer.

Leave a Comment

Convert postcode to longitude and latitude

Usage:

./postcodetolonglat.sh 'SK99 9LZ'

Creates a little temp file called ‘postcode’. The file is put in /tmp and is of course unique for each execution of the program.  These files can be cleared out quite easily as part of maintenance of the /tmp folder. (i.e. a weekly cron that executes

find /tmp -mtime +1 -user apache -exec rm {} \;

where the file will be at least a day old and is owned by apache which (in my case) is the apache user for the apache web server.

Script:

#!/bin/bash
. `/usr/bin/wget "http://maps.google.com/maps/geo?q=$1" -O "/tmp/$1"`
LAT=`cat "/tmp/$1" | awk -F "[" '{print $4}' | awk -F "," '{print $2}'`
LON=`cat "/tmp/$1" | awk -F "[" '{print $4}' | awk -F "," '{print $1}'`
echo "<script language=JavaScript>"
echo "   var Lon=$LON;"
echo "   var Lat=$LAT;"
echo "   var orig='$1';"
echo "</script>"

Then in, say, google maps:

From your browser, call (for example for the Warminster postcode of the R.E.M.E - BA12 0BS)

http://server.com/map4.php?pc=BA12%200BS

The code for map4.php is below.

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <?php
$Postcode= $_GET['pc'];
echo passthru("./postcodetolonglat.sh '$Postcode'");
?>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA2OgjrxQMCCnZOIKNKqdqqxQQ2LfZc7AlgWy0LicD3n_XCYU-EBSRAF96CM-HbX18JJscTSEShXpbfg"
            type="text/javascript"></script>
    <script type="text/javascript">
    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        var gll = new GLatLng(Lat,Lon);
        map.setCenter(gll,17);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        GEvent.addListener(map,"click", function(overlay,latlng) {
          if (latlng) {
            var myHtml = "The GLatLng value is: " + map.fromLatLngToDivPixel(latlng) + " at zoom level " + map.getZoom();
            //map.openInfoWindow(latlng, myHtml);
                alert(gll.toUrlValue(10));
          }
        });

      }
    }
    </script>
  </head>

  <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 100%; height: 100%"></div>
    <div id="message"></div>
  </body>
</html>

Leave a Comment

ImageMagick Annotate/Watermark/Add text to graphic image

Where logo_01.jpg is the source image.
The output image is out.jpg
The text put on is 12345
The font was installed on the system by default and standard TTF which can be found with a basic search FS.

convert logo_01.jpg -fill ‘#0008′ -draw ‘rectangle 5,128,114,145′ -font /usr/share/fonts/bitstream-vera/Vera.ttf  -fill white   -annotate +10+141 ‘12345′ out.jpg

Leave a Comment

mysql autostart runlevel

chkconfig –level 3 mysqld on

chkconfig –list mysqld

service mysqld status

Leave a Comment

compile gtk under cygwin

use this syntax

gcc test2.c -o base2 `pkg-config –cflags –libs gtk+-2.0`

Leave a Comment

Create ISO image of DVD using dd command

dd – convert and copy a file
See man pages for explanation

Create copy of DVD to ISO:

[root@killer media]# dd if=/dev/dvd of=winxp.iso

Create a blank disk image:
dd if=/dev/zero of=/home/disk.img bs=1M count=4096

Leave a Comment

Older Posts »