22 Dec 2016

RELATIONSHIPS

School of Life has been one of the best things I have found in my short 30 years on earth.

Answering questions I did not know how to ask, or know that I even need to ask.

They provide turths that can really help in understanding who we are as people and why we are so weird internally

From their about page.

Description
The School of Life is both a You Tube channel and a real-life school (for adults) devoted to emotional education. We're fascinated by the sort of questions we're never taught enough about at regular school or college: How can relationships go well? What is meaningful work? How can love last? How can one find calm? What's gone wrong (and right) with capitalism?




10 Oct 2015

Finite Math: Set Operations and Notation

26 Aug 2015

I found this usefull info on this site, and had to copy it some where I could find it again. http://accesstech.co.za/?p=2074




Useful USSD codes for South African Mobile networks
USSD codes (Unstructured Supplementary Service Data)
OptionNetworkUSSD CodeFurther instructions and _ or notes
Change Price plan and or tariffMTN*141*4#key in “2” (migrate), then key in a that corresponds with the price plan you’d like to migrate to.
Airtime transferMTN*141*6328* recipient’s cell phone number* rand amount#For example: *141*6328*0731234567*30#).
Airtime transferVodacom*111#Option 4 (bundle or airtime transfer) >> option 1 (airtime) >> choose an amount from R29 to R2000 >> enter a Vodacom number >> Confirm and you’re done.
Airtime transferTelkom Mobile (8ta)*180#Option 2 (transfer airtime) >> choose the amount >> enter an 8ta cell number >> confirm and you’re done.
Request airtimeMTN*141*6328*number of the person sending you airtime#Two requests are permitted per day.
Balance EnquiryMTN*141#Your airtime, SMSs and your MTN internet bundle balance will be displayed.
Airtime rechargeMTN*141* recharge voucher pin #
Data bundle purchaseMTN*141*6#Key in “1” (purchase bundles and services) >> key in “1” (internet bundles) >> key in “1 – 3” (the 3 options are for Volume bundles, duration bundles, and uncapped bundles respectively)
Deactivate an uncapped data bundleMTN*141*5#key in “2”.
Loyalty points programMTN* 141 * 9 * your ID number#A program where MTN rewards its customers with points to buy airtime, bundles, enter competitions etc.
Call chargesMTN*111*2#key in “1 – 2” (the two options are for number and country respectively)
CallbackMTN*121* recipient’s number #You are permitted five callbacks a day on the MTN network.
Check your own number – MSISDN queryMTN*123*888#This will display the number from where this USSD code is dialed.
Check your own number – MSISDN queryVodacom*111*501#This will display the number from where this USSD code is dialed.
MMS OTA settings requestMTN*123*12#You will receive a configuration message to install the settings, if asked for a pin, enter 1234.
WAP/GPRS/Internet OTA settings requestMTN*123*12#You will receive a configuration message to install the settings, if asked for a pin, enter 1234.
Easy rechargeMTN*141*10#
Point of interest requestMTN*120*555#An MTN service to find useful points of interest (POI) located closest to you like an ATM, fast food outlets, movie theatres etc.
Registering/Opening a Mobile Money accountMTN*120*668#You have to be at least 16 years to qualify for this service.
Cancelling a Recurring BundleMTN*141*5#key in “1”.
My Vodacom USSD services menuVodacom*111#this menu includes popular services
Balance EnquiryVodacom*100#your balance is displayed on handset (Prepaid Only)
Airtime rechargeVodacom*100*01*Recharge PIN#Account top up with voucher value (Prepaid Only)
Time Window EnquiryVodacom*100*02#Time Window Expiry date displayed on handset (Prepaid Only)
Vodata Service SetupVodacom*141*777#Vodata Service Setup menu will be installed or removed (Contract & Prepaid)
Please CallMe ServiceVodacom*140*MSISDN#Sending a text message which includes the sender’s number to another cell phone number requesting the receiver to call the sender (Contract & Prepaid)
Please Recharge MeVodacom*140*02*MSISDN#Request airtime from your phone to any Vodacom customer
Airtime transferVodacom*102*02*airtime value*MSISDN#Send airtime from your cellphone to any other Vodacom Prepaid phone
Vodacom PaypointVodacom*120*1234#Enables Vodacom merchants to accept credit card payments using a mobile phone without requiring a fixed line point of sale terminal
Cell C USSD services menuCell C*147#Launches the USSD menu with various account management and inquiry options.
Balance EnquiryCell C*101#Displays the remaining balance on your handset
Airtime rechargeCell C*102*#Account top up with voucher value
Please CallMe ServiceCell C*111*#Sending a text message which includes the sender’s number to another cell phone number requesting the receiver to call the sender (Contract & Prepaid)
Check your own number – MSISDN queryCell C*147*100#(retrieve own number)
Manage subscription servicesCell C*133*1#
Virgin Mobile menuVirgin Mobile*100#Launches the USSD menu with various account management and inquiry options.
Get phone settingsVirgin Mobile*103*1#
Check your own number – MSISDN queryVirgin Mobile*103*2#(retrieve own number)
Change Virgin Mobile PINVirgin Mobile*103*3#
Balance info after callsVirgin Mobile*103*4#
SIM SwapVirgin Mobile*103*5#
Manage airtimeVirgin Mobile*104#
Check balanceVirgin Mobile*101#
Airtime rechargeVirgin Mobile*102* PIN #Account top up with voucher value
Credit card rechargeVirgin Mobile*104*3#You need to register for this service by dialing 123 from your Virgin Mobile device
Transfer airtimeVirgin Mobile*106#You can only transfer airtime to other Virgin Mobile users.
Please CallMe ServiceVirgin Mobile*125*MSISDN#Sending a text message which includes the sender’s number to another cell phone number requesting the receiver to call the sender (Contract & Prepaid)
Voice MailVirgin Mobile*109#
RICA checkVirgin Mobile*124#
BundlesVirgin Mobile*110#Sms, data and Blackberry bundles
Transfer airtimeVirgin Mobile*106#
Recharge meVirgin Mobile*104*5#
Call handlingVirgin Mobile*107#
Airtime advance activationVirgin Mobile*121*4#(Prepaid only)
Roaming callVirgin Mobile*108*MSISDN#




So what is USSD exactly?
Unstructured Supplementary Service Data (USSD) is a technology that allows users to access various services through the use of short codes. It usually consists of a number that start with a * and end with a #.
Customers on prepaid, for example, often use USSD codes to load airtime:
Let’s take MTN as an example:
Load airtime voucher: (*141*VoucherPIN#)
check balances: (*141#)
send a please call me: (*121*CellphoneNumber#).
So, here is a list of USSD codes for all the mobile networks in South Afica.
I will update this list so, yet again, please feel free to provide input regarding errors, ommissions and anything else.


30 Jan 2013

The web is stateless, why you need to refresh the page.

As I deal with people who use computers every day, who don't necessarily understand what is happening. I have decided to try and explain it once in nice simple language so that it is easy to
understand why certain web sites / applications / pages seem to have issues showing the most up-to-date information.

The web is stateless. It has no way of remembering what is happening or what has happened. This is the way it was built from the very lowest levels. It is designed to survive a nuclear war.

What you see on your computer is just a picture or view of the web application or web page at a particular point in time. The time you requested the page you are currently viewing. Your web browser has no way of know if any thing has changed on the server or web page. Unless you ask the server by requesting the page again. You need to refresh the page to see any changes that have been made since you last asked the server.

To make things even more complicated your web browser tries to speed up the time it takes to load pages by caching web pages. If you just viewed a web page your web browsers stores it on your device or computer. If you ask for that page again, instead of fetching the page from our server it will show you the page it stored on your device.

Web developers have developed a number of technologies to work around caching, by telling web browser which pages it can cache and what in a web page it can cache. Though some times this does not always work as expected and thing can be come out of sync. The pages you see are a mix of the old data stored on your device and the new content on the servers.

To make things even more complicated it all comes down to how computers understand time. The time on the server is different from the time on a server sitting in the middle of Russia. Which is also
different from the time on your computer. Even for computer in the same country the time they show can differ by hours if they are not set correctly. So how your web browser caches data, and for how long can be quite different then what our server or web page asked it to.

The point is that the only time that matters when you are working with a web server or web application is the time on the server not on your computer. Bidorbuy provides a way to see this using the follow page, http://www.bidorbuy.co.za/jsp/header/BidorbuyTime.jsp. This page can be found on our site at the very bottom of every page, in the footer under the bidorbuy heading.

http://www.webopedia.com/TERM/S/stateless.html
http://en.wikipedia.org/wiki/Stateless_protocol

http://www.mouseworks.net/refreshbrowser.htm
http://www.refreshyourcache.com/en/cache/
--

https://plus.google.com/u/0/117484568487416046905/posts

5 Sept 2012

Working with log files in the /var/log/ directory Part 3 ssh

Continuing from part 1

Part 3 will deal with using these commands in scripts and over ssh to get some information on remote servers. 

As most of what I wanted to say is covered in an other blog I am provding a link to that blog with some of the important parts cut out.

 http://backreference.org/2011/08/10/running-local-script-remotely-with-arguments/ 

Well, ssh runs a shell on the remote host, so why not do
 $ ssh user@remote < local.sh  

And if your script has arguments
$ ssh user@remote 'cat | bash /dev/stdin arg1 arg2 arg3' < local.sh 
Argument is __arg1__  
Argument is __arg2__  
Argument is __arg3__

Now what would you put inside a script. In my case I have a script that I use to do some basic checks. I will cut out our work specific stuff but you should get a really good idea about what you can do and how to do it. This script is a work in progress please fell free to make changes. 

How I run the script. Use the multiple arguments method

ssh root@192.168.0.51 'cat | bash /dev/stdin -a < ./check.sh


What my script does



 /tmp/check.sh -h
Usage: check.sh [-hvapdbs] [-o arg] args
Options avalible in the script -h Help
  -v version
  -s disable sleep time beween checks

Chose which checks you want to perfom 
  -a (all) checks 
  -p not implemented
  -d defualt linux health checks 
  -w webserver checks
  -l list all the check functions

How to use

ssh root@192.168.0.51 'cat | bash /dev/stdin -a -s' < `basename $0` | tee /somedir/checks_output

The script 



#!/bin/bash

# simple example of how to use this script

# simple script that will run some of the basic checks that need
# to be done on the bob servers. 

# simple boolean to enable or disapable sleep/pauses in script out put 
# set waits=$NULL or waits=  to ensure the test evalues false. 
# how to test
# waits=
# [ $waits ] && echo true
# waits=$NULL
# [ $waits ] && echo true
#
# setting $waits to anything other then null evaluates true
# waits=1
# [ $waits ] && echo true
# true
waits=TRUE
pause=2

#Nicely formated title on checks
title() 
{
    Sstart="\n\e[04;31m="
    Send="=\e[00m\n"
    Sfill="================================================================="
    Stitl="$1"
    Sbuild="$Sstart $HOSTNAME -- $Stitl"
    fill=${#Sbuild}
    #echo $fill
    #echo ${Sfill:fill}
    #echo -e "\e[04;31m= $HOSTNAME ==== $1 =============\e[00m\n"

    Sbuild="$Sstart $HOSTNAME -- $Stitl ${Sfill:fill}$Send"
    echo -e "$Sbuild"
}

# check disk usage on server
disk_check()
{
    title "Checking Disk Space"
    #echo -e "\e[04;31m=$HOSTNAME=====Checking Disk Space===================\e[00m"
    df -h
    [ $waits ] && sleep 3

    # check inodes
    title "Checking Available inodes"
    #echo -e "\e[04;31m=$HOSTNAME=======Checking Available inodes===========\e[00m"
    df -i
    [ $waits ] && sleep 3
}

dmesg_check() 
{
    #dmesg
    title "Checking DMESG"
    #echo -e "\e[04;31m=$HOSTNAME======Checking DMESG========================\e[00m"
    [ $waits ] && sleep 2
    echo "dmesg tail -n 60"
    dmesg | tail -n 60
    [ $waits ] && sleep 8
    echo "summary of dmesg"
    dmesg | sed -e "s/\[[^][]*\]//" -e "s/[0-9]\+//g" | sort | uniq -dc | sort -n
    [ $waits ] && sleep 8
}

mesg_check() 
{
title "Messages Log"
    #cut -d" " -f 4- /var/log/messages | sort | uniq -dc
    #cut -d" " -f 5- /var/log/messages |\
    # sort |\
    # sed -e "s/pid=[0-9]* //"\
    # -e "s/EXIT\: rsync status\=0.*/EXIT: rsync status=0/"\
    # -e "s/last message repeated.*/last message repeated/" |\
    # uniq -c |\
    # sort -n

    sed -e "s/\(.*\)\($HOSTNAME\)/\2/" -e "s/\[[^][]*\]//" -e "s/[0-9]\+//g" /var/log/messages | sort |  uniq -c | sort -n
    [ $waits ] && sleep 5
}

DT_check()
{
    # date
    title "Checking Date & Time"
    [ $waits ] && sleep 3
    date
    [ $waits ] && sleep 3
}

network_check()
{
    # check interfaces for droped packets and errors
    title "Checking Network Interfaces"
    [ $waits ] && sleep 3
    ifconfig
    [ $waits ] && sleep 5
    # check firewall
    echo "Showing ip tables"
    iptables -L
    [ $waits ] && sleep 5
}

crontab_check()
{
    # check the jobs schedule 
    title "Checking Crontab Entries"
    #echo -e "\e[04;31m=$HOSTNAME======Checking Crontab Entries==============\e[00m"
    [ $waits ] && sleep 3
    #find /var/spool/cron/* -printf  \\n%p\\n%t\\n -exec cat {} \;
    find /var/spool/cron/* -printf "\\n\\n%p\\nLast Modified : %t\\nLast Accessed : %a\\n\\n" -exec cat {} \;
    [ $waits ] && sleep 3
    #[ $waits ] && sleep 3
    #[ $waits ] && sleep 3
}

keys_check()
{
# check ssh configuration to make sure it has not changed
    title "Checking Known Hosts"
    [ $waits ] && sleep 2
    cat /root/.ssh/known_hosts 
    echo -e "\n"
    echo -e "\nList of authorized IPs"
    cut -d" " -f1 /root/.ssh/known_hosts | sort -n
    [ $waits ] && sleep 5
    title "Checking Authorized Keys"
    [ $waits ] && sleep 2
    cat /etc/ssh/authorized_keys 
    echo -e "\nList of authorized IDs\n"
    grep -v "#" /etc/ssh/authorized_keys | cut -d" " -f3
    [ $waits ] && sleep 5
}

mail_check()
{
# chech maillog for status not sent should not return any output
    title "Checking Mail Logs"
    [ $waits ] && sleep 3
    echo -e "\nChecking mail logs\n"
    grep -P "(stat|status)=(?"\!"[Ss]ent)" /var/log/maillog
    grep -P "(stat|status)=(?"\!"[Ss]ent)" /var/log/maillog | wc
    #grep -P "stat=(?"\!"Sent)" /var/log/maillog
    #grep -P "stat=(?"\!"Sent)" /var/log/maillog | wc 
    #grep -P "status=(?"\!"sent)" /var/log/maillog
    #grep -P "status=(?"\!"sent)" /var/log/maillog | wc
    [ $waits ] && sleep 3
}


apache_check()
{
    # Apache Error Logs
    title "Checking Apache"
    if  [ -e /var/log/httpd/error.log ]
    then
        [ $waits ] && sleep 2
        #sed -e "s/\[[^][]*\]//g" -e "s/[0-9]\+//g" /var/log/httpd/error.log | sort | uniq -c | sort -n
        title "Sumary of httpd error"
        #echo -e "\n Sumary of httpd error messages"
        sed -e "s/\[[^][]*\]//g" -e "s/ referer:.*//" -e "s/[0-9]\+//g" /var/log/httpd/error.log | sort | uniq -dc | sort -n
    #sed -e "s/\[.*\]\([^:]*\)\(.*\)/\1/" /var/log/httpd/error.log | sort | uniq -dc | sort -nr
    #sed -e "s/\[.*\]\([^:]*\)\(.*\)/\1/" /var/log/httpd/error.log | sort | uniq -u | sort -nr
        #grep "phpmyadmin" /var/log/httpd/error.log
        [ $waits ] && sleep 5
    else 
        echo -e "no apache error logs at /var/log/httpd/error.log\n"
    fi
}



all_checks()
{
disk_check
dmesg_check 
mesg_check 
DT_check
network_check
crontab_check
keys_check
mail_check
apache_check

}

default_checks() 
{
disk_check
dmesg_check
mesg_check
DT_check
network_check
crontab_check
keys_check
mail_check

}


checks()
{
#g/()/

checklist=$(cat <
title() \n
disk_check()\n
dmesg_check() \n
mesg_check() \n
DT_check()\n
network_check()\n
crontab_check()\n
keys_check()\n
mail_check()\n
apache_check()\n
checks()\n

EOF
)
echo -e $checklist

}


USAGE="Usage: `basename $0` [-hvapdbs] [-o arg] args"
USAGED=$(cat <
Options avalible in the script
\t-h  Help\n 
\t-v  version\n
\t-s  disable sleep time beween checks\n

\nChose which checks you want to perfom \n
\t-a  (all) checks \n
\t-p  not implemented\n
\t-d  defualt linux health checks\n
\t-w  webserver checks\n
\t-l  list all the check functions\n

\nHow to use\n
ssh root@192.168.0.51 'cat | bash /dev/stdin -a < ./check.sh | tee /somedir/server_report\n
EOF
)


# Parse command line options.
while getopts hvsabdwtlo: OPT; do
    case "$OPT" in
    h)
        echo $USAGE
        echo -e $USAGED
        exit 0
        ;;
    v)
        echo "`basename $0` version 0.4"
        exit 0
        ;;
    s)
        waits=
        ;;
    o)
        OUTPUT_FILE=$OPTARG
        ;;
    a)
        echo "doing all checks"
        all_checks
        exit 0
        ;;

    b)
        echo "doing bob checks"
        bob_checks
        exit 0
        ;;

    p)
        echo "doing all checks"
        all_checks
        exit 0
        ;;
    d)
        echo "doing default checks"

        default_checks
        exit 0
        ;;
    w)
        echo "doing apache checks"
        apache_check

        exit 0
        ;;
    l)
        echo "showing all checks"
        checks
        exit 0
        ;;

   \?)
        # getopts issues an error message
        echo $USAGE >&2
        exit 1
        ;;
    esac
done

# Remove the switches we parsed above.
shift `expr $OPTIND - 1`

# We want at least one non-option argument.
# Remove this block if you don't need it.
if [ $# -eq 0 ]; then
    echo $USAGE >&2
    exit 1
fi

# Access additional arguments as usual through
# variables $@, $*, $1, $2, etc. or using this loop:
for PARAM; do
    echo $PARAM
done

# EOF