Unsuccessful Post attempt(s) – BIOS

Don’t believe the hype.  Just as soon as you get an unofficial title of “expert” with your friends and family, they will throw you for a loop.  I was sitting at my desk when I received a phone call from a friend.  I should feel proud that he values my opinions more than his IT department, but not this time.

About a second later my inbox beeped and the following picture showed up.

bios-error

I was in the middle of dealing with restful web development and couldn’t get my head around the error.

Daniel                What does this mean?

Me                     Difficult to say, what happened?

Daniel                I don’t know.

Me                     Did you install anything?

Daniel                No, well, I don’t think so

Me                      Did anything change?

Daniel                 No ….

We did speak a bit longer but I couldn’t get any sense of the situation and suggested he speak with IT.

After work, did a bit more checking, there are a couple of possible reasons.

  • Incorrect memory type for that computer
  • Possible buggy version of BIOS (that was just installed)
  • Some other hardware problem

It could be any of these, but without more information it is not possible to get more specific.  If you were installing new hardware or adding more memory that might be a clue.  Another clue might be that your computer is having problems with the hardware that perviously either always existed (always left on) or never existed until after the boot (always off).

My mentor suggested that perhaps it was a problem with the CMOS battery and some of the settings may have gotten lost.

What is POST?  Power On Self Test.

What was the problem?  I guess I will never know, I simply heard that IT was working on the machine for quite a while and then left without saying a word.

 

Posted in Soapbox | Tagged | Comments Off on Unsuccessful Post attempt(s) – BIOS

command line fun – testing for existence

I remember quite some time ago when I was developing a an application when the personal computer was actually fairly slow.  Of course I happened to pick a technology that worked just fine on a newer computer but it actually ran quite pokey on my machine.

The decision was made to never develop on a machine less than or equal to the target platform.  Fast forward a few years to discover that I periodically get stuck with the slow development environment and there is nothing that I can do about it.

Well, I can’t speed up the machine but I can make my programs and scripts a bit smarter.  The target of my focus was a small script that called some horribly inefficient java program.  Not all the programs dawdled, just this one.

The problem was the script called this program even though in most cases the input directory was empty – not a problem on production but really slow on development.

The input directory can hold quite a few data files and the names are never the same.  I ran through a few different ideas.

Idea #1

Well, it seems to be a pretty strait forward solution.  Get a count of the number of files and then you will know how many things there are to process and thus if there is anything to process.

It almost makes sense until you try this.  It works just great when data does exist but when no data exists then it doesn’t work very well.

#!/bin/bash

EXT=xml
INPUT=/data/input

CNT=`ls -1 $INPUT/*$EXT | wc -l`
if [ $CNT -gt 0 ]
then
 echo $CNT items
else
 echo "files don't exist"
fi

The count variable is set to zero but the the shell informs us that no data exists.

ls: cannot access /data/input/*xml: No such file or directory

Not a serious issue but depending on the person very distracting.

 

Idea #2

This error message can be easily gotten rid of.  Simply redirect the error output to a file or to /dev/null.

#!/bin/bash

EXT=xml
INPUT=/data/input

CNT=`ls -1 $INPUT/*$EXT 2>/dev/null| wc -l`
if [ $CNT -gt 0 ]
then
 echo $CNT items
else
 echo "files don't exist"
fi

Not a bad idea if you know that the directory permissions for the input directory will always be OK.  If not, then you will be (possibly) throwing away the only help to diagnosing an odd behavior.

testing existence – Extra credit edition

This second solution is quite acceptable and unless it is called a lot it shouldn’t be too much overhead.  Yet there is a much easier solution that is probably even more efficient.

#!/bin/bash

EXT=xml
INPUT=/data/input

ls $INPUT/*$EXT >/dev/null 2>&1  
if [ $? -eq 0 ]
then
 echo $EXT files exist
else
 echo "$EXT files don't exist "
fi

No, you don’t know the number of files, but you don’t have to create a pipe and fill it with a few (or many) files just to decide whether or not to run a program.  Simply look at the Unix return code from our last command, if zero, then we know our files exist.

Posted in Command line, programming | Tagged , | Comments Off on command line fun – testing for existence

command line fun – transferring data with sftp

I must admit that I misunderstood the task when I first saw it.  The vendor had changed how they provide the data.  We will no longer be able to retrieve the data using ftp – the data should be picked up with sftp.

I immediately thought that this would be quite the trick as as far as I was aware you cannot script sftp the same way you can ftp.  I was discussing this with my boss to get yet another dose of information.  My boss said that this seemed an odd choice of technology, that what would be a better choice would be to use ftps.

It was about this time that I realized that I made the first mistake of thinking about the programs not the protocols.  Indeed there are three different protocols, FTP, SFTP and FTPS and there are two programs with the same name as the protocol.  The second mistake was that I was not familiar with the FTPS protocol.  First a bit about the protocols.

File Transfer Protocol (FTP)

The FTP protocol is to connect to the server with two connections.  The first is the command connection which controls the transfers, and the second connection is the data connection.  The process is controlled over one while the data is transferred over the second connection.

Although the setup of the ftp server can be anything the typical setup uses ports 20 and 21.

The ftp client connects from the client computer on port “X” to the server using TCP on port 21.  Once the connection has been made a second connection will be used to for transferring the data.  The way this second connection is made depends on the type of mode that is used – active or passive.

Active Mode

The second connection is actually made by the server from port 20 to port X + 1 on the client.

It is really simple, but this won’t usually work in practice at most serious companies as usually there are firewalls protecting the server from the internet.  The firewalls only job is to prevent unknown computers to connect to the machine and thus would prevent the active ftp from working.

This problem was foreseen and thus the passive mode was also created.

Passive Mode

Passive mode is exactly the same as the active mode except that the client opens the second connection instead of the server.  It is because the client opens the second connection that usually eliminates the problem of the firewall interfering with the creation of the connection.

The coordination of how to keep the connections connected is pretty simple.  When the ftp client initiates the passive mode with the command PASV, it receives the number of the port to connect to for the data connection.

Advantages

  • No size limitation on file transfers
  • Some clients can be scripted

Disadvantages

  • Usernames, passwords and files are sent in clear text
  • Filtering active FTP connections is difficult on your local machine (passive is preferred)
  • Servers can be spoofed to send data to a random port on an unintended computer

The big disadvantage to the ftp protocol is that the user and password is communicated as clear text.  It is possible for anyone sniffing packets to get this information.

 

FTPS (or FTPES or FTP-SSL)

The ftp program allows the user to transfer files and change directories on the remote computer.  It is really useful.  When the only real weakness of the file transfer protocol is that the users credentials are passed over in clear text, it seems small enough to correct.

Indeed that is exactly what was attempted with FTPS extensions to the file transfer protocol.  The change was to simply add encryption to plug this particular weakness.  So the change that was done was adding Transport Layer Security and Secure Sockets Layer encryption protocols.

Advantages

  • Provides services for server-to-server file transfer
  • SSL/TLS uses X.509 certificate to authenticate

Disadvantages

  • Requires a DATA channel, which can make it hard to use behind the firewalls
  • Doesn’t define a standard for file name character sets
  • Not all FTP servers support SSL/TLS

 

Secure File Transfer Protocol (SFTP)

The SFTP protocol is also sometimes referred to as SSH File Transfer Protocol.  The SFTP protocol is a network protocol that provides file access, file transfer and file management over a network connection.

All data that is transferred between the client and server, including login credentials, are encrypted. This is usually done through the user of public and private keys but can be done in addition to a user and password.

The file transfer protocol uses only a single connection over port 22 on the server.  Both the commands and data transfer take place over this single connection.

Advantages

  • Only one connection is needed (no special DATA connection)
  • The connection is always secured
  • The protocol includes operations for permission and attribute manipulation, file locking and more functionality

Disadvantages

  • SSH keys are harder to manage and validate

 

Putting it all to good use

The file transfer protocol actually is not the most secure protocol due to the fact that the user credentials are sent over as clear text.  This is actually important if you actually think that someone may be sniffing your packets (not so likely) but depending on the service this might not be so important.

If the data that is transferred to the FTP server is encrypted then it may not be as important if the username and password is captured.  If on the destination server the data is processed and then removed this may not be a problem or if the data is really well encrypted this might not be a problem.  Perhaps the information is public information and if the data escapes it is not important (ie. which days are public holidays for a specific trading calendar, what is the trading price of a stock or what is a company’s PE ratio)

A simple scripted solution using ftp

#!/bin/bash
USER=richard
PASS=secretpasscode
DATA=/var/tmp/datafile.tar

ftp -i -n ftp.somedomain.co.uk <<MARK
user $USER $PASS
pwd
cd data
bin
hash
put $DATA
ls -ltr
MARK

echo file transferred

This is a small script, which despite not being very secure, makes a small connection and puts a data file.  It is only possible because the input to the ftp command can be piped in.  This is done in this clever little script be redirecting the data from the script itself.

It is not possible to do this same trick using the sftp program, but it is possible to create a script using secure copy.

#!/bin/bash
USER=richard
MACHINE=192.168.178.57
DATA=/var/tmp/datafile.tar

scp $DATA $USER@$MACHINE:/tmp 

This script is even smaller than the ftp script and is more clear to the casual reader.

The scp command actually still requires a password and is not “scriptable” in the same way that the ftp client was.  However, it is possible to setup the user setup so the public/private key is used for authentication and password isn’t necessary.

 

ftp Scripting – Extra credit edition

For the really paranoid who must continue to use ftp, you might not want to connect directly to a server over the internet but instead connect via a proxy server.  It is possible to do that using ftp.  Simply pass all the information necessary for the proxy server.

#!/bin/bash

#our destination machine
USER=dick
PASS=secretpasscode
DEST=ftp.somedomain.co.uk

#our proxy server
PROXYUSER=bob
PROXYPASS=secret
PROXYMACH=myproxy.mydomain.com
DATA=/var/tmp/datafile.tar

ftp -i -n $PROXYMACH <<MARK
user $USER@PROXYUSER@DEST $PASS@$PROXYPASS
cd data
bin
hash
put $DATA
ls -ltr $DATA
MARK

echo file transferred

Although it is possible to add this level of complexity to buffer your server from the ills of the world, it really wouldn’t be more secure than to use secure copy (scp) for transferring the data files.  Secure copy would have encrypted credentials and the key used as a “password” would most likely be considerably longer and more secure than any normal password.

Even if you picked a small 256bit key, it would on average still be better than some 16 or 20 character  login.  Yet, a more reasonable choice of a 1024 or 2048 bit key would be massively more secure than any password selected.

Nice explanation of active / passive ftp
http://www.slacksite.com/other/ftp.html

Posted in Command line, programming | Tagged , , | Comments Off on command line fun – transferring data with sftp

The last version of windows – ever!

A little over a year ago, I was reading about how windows 10 would be the last OS upgrade that I will ever need.  It is understandable that Microsoft wishes that people switch to their latest operating system and those darn users are reticent to change.  Especially when Microsoft provides an operating system that already works up to the users expectations.

This is a fairly intractable situation.  Make an operating system that people don’t like and they will moan about how terrible it is, words gets around and nobody buys it;  the alternative is that you make an operating system that works fine and people don’t want to upgrade to the next new operating system 3 years later.

An interesting solution to the whole upgrade treadmill was the mention of Windows as a service.  It simply would continuously update and upgrade to remain current.  No more new releases of windows.  It sounds like a pretty big order.  How will they bring out a new file system formats?  Do they simply convert it when that feature is released? What if the disk is virtually full?  Do they support one file system standard for machines installed today and another in three years?

Yet, as a developer I know how nice it is to leave something old behind and re-design it from scratch.  Similar arguments could be made about changes to the GUI or driver model.

Is Windows 10 is as good as it gets.  No more innovation possible?

Maybe, but in January I was reading an article that in the future only the most critical security fixes will be made available for those (windows 7 and 8.1) platforms.  An even more bold statement suggests that the operating system will be closer tied the the hardware.

Going forward, the company says that using the latest generation processors will always require the latest generation operating system.

This seems contradictory to me.  This is the last operating system that I will need, well, unless my machine gets old.  If that happens the critical patches will be installed up to the dates that have been promised but no longer.  If you are a windows 7 user you should see these patches until January 14, 2020.

That is a long time but it sounds like it would be really locking the company into a single code base that acts different and has different levels of security depending on the age of the machine.  It is really no different than the situation that Microsoft has now but they will have to keep it forever.  No reprieve of a new code base for the new Windows N.

I personally hope to have a new machine in 2020 anyway.  Perhaps it will be a 7gz 16 core with 500Tb SSD storage.  I can really word-process on a machine like that.

http://www.eweek.com/pc-hardware/microsoft-says-windows-10-will-be-the-last-os-upgrade-youll-ever-need.html

http://arstechnica.com/information-technology/2016/01/skylake-users-given-18-months-to-upgrade-to-windows-10/

Posted in Soapbox | Tagged | Comments Off on The last version of windows – ever!

safe computing – email

What is computer security?  Techniques for ensuring that computer data is not accessed by unauthorized individuals. This might involve passwords, encryption or physical seclusion.

Virtually every other week there is a story in the news about some web site which was hacked and hundred of thousands of user/password combinations taken.  When these incidents are announced there are only two things that might be considered important.

The main concern should be whether any real user data such as name, address, banking details or other personal non-public data escapes.  The secondary concern is that now someone knows your username  and password.  This shouldn’t be a problem as after all, everyone uses a different username and password at each website – right?   Well, no and that is part of the problem.

It was a stroke of genius to use email addresses as the user id for all of these sites because email addresses are a unique piece of information.  You don’t have to worry that there will be two bobjohnson@outlook.com, between the email name and the domain they form a unique id.

Why millions of passwords on the loose is a problem is because once people find a good password a lot of them simply use it again and again at every site they go to.  This means when your password is compromised at bobsindojapansegrill.com, they know your user name and password that you might be using at Facebook, Gmail or some other site.  There are apparently people who like the challenge or the rewards of hacking other people’s accounts.

To feed on rational fears it can be even worse than that.  The “bad men” don’t even need your password to compromise your account as knowing your email address may be enough.  Given a free choice, people are pretty bad at picking secure passwords.

This is a list of some of the most common passwords from 2014.

1. 123456
2. password
3. 12345
4. 12345678
5. qwerty
6. 123456789
7. 1234
8. baseball
9. dragon
10. football
11. 1234567
12. monkey

It is quite likely with this list of passwords, a hundred email addresses and a handful of websites you will fine one or more that will let you in.  At work, well especially at large companies, they tend to espouse a number of rules designed to create difficult to guess passwords.

1. minimum of 8 characters
2. must include one upper case letter, one lower case letter, one digit and one symbol
3. must be different than the the last 12 passwords
4. cannot include the name of the account
5. cannot include the users name
6. does not include a complete word
7. doesn't include name of family or extended family
8. must include the sound you hear when stepping on a bug*
9. must be impossible to represent the password with any keys on a keyboard*
*included to see if you read the entire list.

The IT department want things to be really really secure so if you are unlucky you will have a different password for every internal system that you use and it will seem that they change every three weeks.

It is almost impossible to have a few dozen passwords that change on this type of schedule without writing them down somewhere.   Yet there is obviously a good way and a bad way to do that.

monitor-with-password2Your password on a sticky note on your screen or the corner of the desk are about as bad as it gets.  I have heard of people storing their passwords in text files, word documents, or in excel spreadsheets.  This is a slight step up from the password boldly written across the screen but not as good as something a bit more secure.  This could be either password protected word or excel document.  Not a great choice but should keep your secrets for the casual snooper.

Yet, there is a dedicated program, a password manager, which is designed for the task of tracking this type account information.  Depending on the program it may use either 128bit or 256 bit encryption keys.  This is much better than the more limited 40 bit key limitation for encryption that existed for so long in the USA.  While it would take millions of years to break 256bit keys the much shorter 56bit key has been broken in only four months and that was in 1998 with a 90mhz Pentium.

Yet even the password manager can be a vector for weakness to the security of your password information.  What makes these tools convenient is that they store your user and password information and it to make it convenient the password can be copied to the clipboard.  Once this happens this information is available to be sniffed by other applications running on your phone.

I wish that last part could be labeled a paranoid fantasy but is a weak point regardless of the platform (sorry IOS fans).  Yet the password manager is safe if you read and remember the password and manually type it into the application that needs it.

Posted in Soapbox | Tagged | Comments Off on safe computing – email

command line fun – juliane day number to gregorian

In a previous blog, I implemented a routine to convert a Gregorian date into a Juliane day number to allow simple math and comparisons on dates.

This was pretty cool but it is less useful if you cannot convert back into a user friendly version of the date.

The conversion routines in the wikipedia entry also cover converting back to a Gregorian day, month and year.  I have also implemented a routine to calculate the day of the week.

#!/bin/bash

# https://en.wikipedia.org/wiki/Julian_day#Converting_Julian_or_Gregorian_calendar_date_to_Julian_day_number

twodig()
{
  val=$1
  retval=$val

  if [ $val -lt 10 ]
  then
    retval=`echo 0${val} `
  fi
  echo $retval
}

# div = floor(dividend / divisor)
div()
{
  echo $(( $1 / $2 ))
}
# quotient = dividend / divisor
modulo()
{
 echo $(($1 % $2))
}

# the lowest whole number
floor()
{
  X=$1
  echo ${X%.*}
}

# day of week name
dayofweek()
{
  expr=$1

  case $expr in
   1) retval=mon;;
   2) retval=tue;;
   3) retval=wed;;
   4) retval=thr;;
   5) retval=fri;;
   6) retval=sat;;
   7) retval=sun;;
   esac

   echo $retval
}

# ordnal number of day of week
dayofweekIdx()
{ 
  idx=`modulo $1 7`
  idx=`echo "$idx + 1" | bc -l`
  echo $idx
}

#####################################################################################################
# calculate the actual gregorian day/month/year from the julian value                               #
#####################################################################################################
getGregorian()
{
  J=$1

  y=4716
  v=3
  j=1401
  u=5
  m=2
  s=153
  n=12
  w=2
  r=4
  B=274277
  p=1461
  C="(−38)"


  # 1.
  #
  # f = jd + j + ((   ( 4 * J + B)   div 146097) * 3) div 4 + C
  #echo "f = $J + $j + ((   ( 4 * $J + $B)   div 146097) * 3) div 4 + $C"
  tmp=`echo "4 * $J + $B" | bc -l`
  tmp=`div $tmp 146097`
  tmp=`echo "$tmp * 3" | bc -l`
  tmp=`div $tmp 4`
  tmp=`echo "$J + $j + $tmp - 38" | bc -l`
  f=$tmp
  #echo f $f


  # 2.
  #
  # e = r * f + v
  #echo "e= $r * $f + $v "
  e=`echo "$r * $f + $v " | bc -l`
  #echo e $e


  # 3.
  #
  # g = mod (e,p) div r
  #echo "g = mod ($e,$p) div $r"
  g=`modulo $e $p`
  g=`div $g $r`
  #echo g $g


  # 4.
  #
  # h = u * g + w
  #echo "h = $u * $g + $w"
  h=`echo "$u * $g + $w" | bc -l`
  #echo h $h

  # 5.
  #
  # D = (mod(h,s)) div u + 1
  #echo "D = (mod($h,$s)) div $u + 1"
  D=`modulo $h $s`
  D=`div $D $u`
  D=`expr $D + 1`
  D=`twodig $D`
  #echo D $D


  # 6.
  #
  # M = mod(h div s + m, n) + 1
  #echo "M =  mod($h div $s + $m,$n) + 1"
  M=`div $h $s`
  M=`expr $M + $m`
  M=`modulo $M $n`
  M=`expr $M + 1`
  M=`twodig $M`
  #echo M $M


  # 7.
  #
  # Y =  (e div p) - y + (n + m - M) div n
  #echo "Y =  ($e div $p) - $y + ($n + $m - $M) div $n"
  Y=`expr $n + $m - $M`
  Y=`div $Y $n`
  tmp=`div $e $p`
  Y=`expr $tmp - $y + $Y`
  #echo Y $Y

  echo $Y$M$D
}

JD=2451545
USERDATE=`getGregorian $JD`
IDX=`dayofweekIdx $JD`
DAYOFWEEK=`dayofweek $IDX`
echo $USERDATE is a $DAYOFWEEK

idx=0
while [ $idx -lt 15 ]
do
  JD=$((2451554 + $idx))
  IDX=`dayofweekIdx $JD`
  DAYOFWEEK=`dayofweek $IDX`
  echo $JD $IDX $DAYOFWEEK

  idx=$(($idx + 1))
done

 

Posted in Command line, programming | Tagged , | Comments Off on command line fun – juliane day number to gregorian

command line fun – julian day number

I keep getting into a situation where I need to do some simple date calculations.  This is not a problem using a language like Java or when using a language that lets you add additional modules like Perl.  Unfortunately, some of the tasks I get at work don’t allow me the luxury of choosing which technologies are available to me.

Yet the algorithms themselves are usually pretty well defined and can be recreated in a different language if needed by.  In this particular case, the problems of calculating using dates is not unique and has been solved a long time a ago by astronomers.  The solution was to start counting at zero at the beginning of the calendar and each day following day is increased by an additional value.

The Julian Day Number (JDN) is the integer assigned to a whole solar day in the Julian day count starting from noon Greenwich Mean Time, with Julian day number 0 assigned to the day starting at noon on January 1, 4713 BC, proleptic Julian calendar

This is all described on the wikipedia webpage, but more interesting than knowing how astronomers thought about their problems is all of their calculations that allow you to convert your normal Gregorian date into a Juliane Day Number.

Once the date is converted, you can then do simple math between the two dates to find the difference in days.  It is a simple matter of adding a integer to see what the date is after that calculation or even what day of the week that day is.

A bash script that can do date calculations may not necessarily be the most efficient technology decision, but it is portable and when not needed for high volume processing may be right solution for a particular job.

Besides, it is fun and all that is necessary is the ability to perform a few calculations, I have a small explanation of both floating point and integer math in bash in another article.

#!/bin/bash

# https://en.wikipedia.org/wiki/Julian_day#Converting_Julian_or_Gregorian_calendar_date_to_Julian_day_number

# div = floor(dividend / divisor)
div()
{
  echo $(( $1 / $2 ))
}
# quotient = dividend / divisor
modulo()
{
  echo $(($1 % $2))
}

# the lowest whole number
floor()
{
  X=$1
  echo ${X%.*}
}

#####################################################################################################
#                                                                                                   #
# a = floor ((14 - month)/12)                                                                       #
# y = year + 4800 - a                                                                               #
# m = month + 12a - 3                                                                               #
#                                                                                                   #
#      aa            bb                cc        dd             ee               ff          gg     #
#JDN = day + floor ((153m + 2) / 5) + 365y + floor (y/4) - floor (y/100) + floor (y/400) - 32045    #
#####################################################################################################

getJulian()
{
  YEAR=$1
  MONTH=$2
  DAY=$3

  a=`echo "(14 - $MONTH) / 12" | bc -l`
  a=`echo 0${a}`
  a=`floor $a`
  y=`echo $YEAR + 4800 - $a | bc -l`
  m=`echo "$MONTH + 12 * $a - 3" | bc -l`
  #echo a $a
  #echo y $y
  #echo m $m


  aa=$DAY
  #echo aa $aa

  bb=`echo "(( 153 * $m + 2) / 5)" | bc -l `
  bb=`floor $bb`
  #echo bb $bb

  cc=`echo "365 * $y" | bc -l`
  #echo cc $cc

  dd=`echo "$y / 4" | bc -l`
  dd=`floor $dd`
  #echo dd $dd

  ee=`echo "$y / 100" | bc -l`
  ee=`floor $ee`
  #echo ee $ee

  ff=`echo "$y / 400" | bc -l`
  ff=`floor $ff`
  #echo ff $ff

  gg=32045
  #echo gg $gg

  JDN=`echo "$aa + $bb + $cc + $dd - $ee + $ff - $gg" | bc -l`
  #echo JDN $JDN
  echo $JDN
}

day=1
month=1
year=2000
val=`getJulian $year $month $day`
echo $val
echo .

for i in 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
do
  val=`getJulian $year $month $i`
  echo $val
done

This is not the only formula to do the conversion from a Gregorian date to a Juliane day number.

Depending on the sources of your algorithm not all Julian day numbers will be compatible.

Posted in Command line, programming | Tagged , | Comments Off on command line fun – julian day number

Analyzing web traffic

Are we alone in the universe?  Well, that question is up for grabs but the question of am I alone on the Internet is quite answerable.   Simply Google any noun or term and it is easy to see that you are not alone.

How to see if your web site is being visited is another question that Google can provide an answer for you – that solution is to use Google Analytics.

Google analytics is a free service for tracking and reporting on the visitors to your site.  According to wikipedia it is the most widely used analytics on the Internet. Getting setup with Google analytics is really easy.  Simply get a Google account and sign into the analytics site enter your web information and get assigned a tracking id.

It is actually not difficult at all, go to the site, login and fill out the application with your websites information.

analytics-signupThere is a small piece of code that you will need to put into your php code so you are tracked.

<script>
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-12359876-1’, ‘auto’);
ga(‘send’, ‘pageview’);

</script>

There are a number of different sites giving an explanation of what you need to do in order that the analytics code is properly tracked.

I don’t actually understand this snippit, but you can see near the end of the script that it contains your sites own code, UA-1235987-1 which in this example was given to us by Google, and is the key to how your statistics are being tracked.

This actually isn’t my code, you should probably be careful about publishing your Google code other than via your web page code.

Depending on your level of coding experience, what type of web site you have this is all the information that you need.  If not take a quick look for some assistance via Google.

Who is out there

What is interesting is not entirely how many people are out there, but what information is apparently being tracked when you visit this or any other site with these analytics embedded in them.

There are a lot of different things that can be tracked the most interesting thing was to view by location, browser/operating system and language.

analytics-location

These seem to be pretty reasonable things to track, but I was also surprised to see without any special setup of the analytics it was also capable of tracking

  • Screen resolution
  • Screen colors (24bit vs 32bit)
  • Flash version
  • Java support
  • type of device (desktop, etc)

I was surprised to see that it was also possible to enable tracking by age and by sex.  I didn’t intend to go any further to invade the privacy of investigate my viewers.  I was however, pretty amazed at what can be tracked and how easy it is to get started.

analytics-browsers          analytics-language

I did see some Windows users and I did see some Linux users, but no Apple users.  I guess they aren’t my target audience.

 

Here is some more information about Google Analytics.

https://support.google.com/analytics/answer/1008015?hl=en&ref_topic=3544906

Posted in blogging, Setup From Scratch | Tagged , , , | Comments Off on Analyzing web traffic

command line – stupid date tricks

Just because you can do something doesn’t mean that you should do it.  I try and keep to that simple rule but from time to time it is fun to see what crazy things you can do in a simple shell script.

Easter is one of those holidays that does not fall on a fixed date each year.  There is a fairly complicated formula to calculate the Easter weekend.

All that is needed to calculate Easter is integer math.  I described how to perform simple math in a bash shell in a previous blog entry.

# https://en.wikipedia.org/wiki/Computus
# anonymous Gregorian algorithm

twodig()
{
  retval=$1
  if [ $1 -lt 10 ]
  then
    retval=0$1
  fi
  echo $retval
}

easter()
{
  Y=$1
  a=$(( $Y % 19 ))
  b=$(( $Y / 100 ))
  c=$(( $Y % 100 ))
  d=$(( $b / 4 ))
  e=$(( $b % 4 ))
  f=$(( ($b + 8) / 25 ))
  g=$(( ($b - $f + 1) / 3 ))
  h=$(( (19 * $a + $b - $d - $g + 15) % 30 ))
  i=$(( $c / 4 ))
  k=$(( $c % 4 ))
  l=$(( (32 + 2 * $e + 2 * $i - $h - $k) % 7 ))
  m=$(( ($a + 11 * $h + 22 * $l) / 451 ))

  month=$(( (($h + $l - 7 * $m + 114) / 31) ))
  month=`twodig $month`
  day=$(( (($h + $l - 7 * $m + 114) % 31) + 1 ))
  day=`twodig $day`

  echo $Y$month$day
}

for i in 2008 2009 2010 2011 2012 2013 2014 2015
do
  easter $i
done
Posted in Command line | Tagged , | Comments Off on command line – stupid date tricks

command line junkie – speed test

Graphical operating systems really does make it easier to multi-task, especially for people who are not comfortable on the command line.  It is really easy to switch between your spreadsheet, web browsers and photo viewer programs in this type of environment.

I suppose a tabbed browser is a logical extension of that metaphor and it does make it easy to open up quite a few pages at the same time.  I probably even open too many sites and periodically my connection seems overly slow.  This would explain why from time to time my browsing comes to a standstill.  It could be that I am overwhelming my bandwidth or someone else in our household is watching you-tube or perhaps even downloading a Linux distribution without my knowledge.

In the true fashion of the user, it is easier to blame your ISP than to investigate the real source of the problem.  As that is usually the position I usually take, my first step is usually to check my connection.

Google will return quite a number of different speed tests that you can use to test the connection from your browser.  I actually find the command line a quicker and easier to check as there is always one open and especially because I never bother to bookmark a speed test.

Debian has a package which will allow me to perform my own speed test without a browser.  It is easy enough to install it using apt-get.

# apt-get install speedtest-cli
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
speedtest-cli
0 upgraded, 1 newly installed, 0 to remove and 26 not upgraded.
Need to get 12.3 kB of archives.
After this operation, 91.1 kB of additional disk space will be used.
Get:1 http://ftp.de.debian.org/debian/ jessie/main speedtest-cli all 0.3.1-1 [12.3 kB]
Fetched 12.3 kB in 0s (108 kB/s)
Selecting previously unselected package speedtest-cli.
(Reading database ... 124629 files and directories currently installed.)
Preparing to unpack .../speedtest-cli_0.3.1-1_all.deb ...
Unpacking speedtest-cli (0.3.1-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up speedtest-cli (0.3.1-1) ...

The command is great.  Simply type speedtest from the command prompt to find out about the upload and download speeds.

# speedtest
Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from Deutsche Telekom AG (79.243.68.175)...
Selecting best server based on latency...
Hosted by Base-Mail (Frankfurt) [6.98 km]: 27.114 ms
Testing download speed........................................
Download: 13.10 Mbits/s
Testing upload speed..................................................
Upload: 7.26 Mbits/s

Oddly enough this worked just fine for a few days but then ceased to work.  After some investigation, I cannot understand why this either worked briefly or why it stopped working at all.  Yet the fix is pretty simple I discovered it on one of the forums.

Just do a small change to the speedtest_cli.py in the /usr/lib/python2.7/dist-packages directory.  The fix is to change the name of the URL that is being called – the change is one line 345.

From

uh = urlopen(‘http://www.speedtest.net/speedtest-servers-static.php’)

To

uh = urlopen(‘http://c.speedtest.net/speedtest-servers-static.php’)

This is a convenient tool if you are concerned about checking your Internet throughput at a given time.

I haven’t needed to track my available throughput over the course of the day, but with this tool it wouldn’t be too much of a task to write up a small script which would run this command every five minutes and save the statistics to a file.

# speedtest | egrep "Download|Upload"
Download: 46.27 Mbits/s
Upload: 8.75 Mbits/s

Perhaps one of these days I will write up such a script.

Posted in Command line, Setup From Scratch | Tagged , | Comments Off on command line junkie – speed test