How to prevent a script from being run more than once at any time

How to prevent a script from being run more than once at any time

This will prevent more than one instance of this script from running at any given time

#/bin/sh

LOCK_FILE=/var/run/${0##*/}.lock

if [ -e $LOCK_FILE ]; then
  OLD_PID=`cat $LOCK_FILE`
  if [ ` ps -p $OLD_PID > /dev/null 2>&1 ` ]; then
    exit 0
  fi
fi
echo $$ > $LOCK_FILE

# do your thing here

rm -f $LOCK_FILE
Advertisements

GOTO

Today I used a GOTO! and before you all step back aghast with horror, it was for a DOS batch script to create a ‘while’ loop – ’nuff said.
Still, it’s been quite a while since i’ve needed one of them!

Akadns and things that annoy me

Akadns and things that annoy me

What do you love about akadns? <silence hovers the sky> akamai’s dynamic global geo-content location system seems a great idea until you have to work with it in practice.

Fast Flux DNS is great to avoid DDOSers and the likes, but it’s a b*st*rd to ‘lock-on’ to for legit traffic

It seems that it fails in two ways:-

1) Firewalls which only support IP ACLs can’t cope with the dynamic nature of the IP hopping employed by the Geo-CDNs.

2) Firewalls which support DNS ACLs cache the result (often incorrectly and for too long) which ends up with a majority of failed connection attempts.

An epic fail on both counts

Interesting though – did anyone else notice that the akadns serial number is always that of UNIX time? (e.g. seconds since epoch of 1/1/1970), as such in their schema it is always the most up-to-date version available

Solution?: 0-second TTL for the alias A/CNAME/MX record?

Shell Tricks part 2 – Why having the current working directory in your PATH is a bad idea

Why having the current working directory in your PATH is a bad idea

Heres’s an interesting consequence of having the current directory in your path:-

$ PATH=$PATH:.
$ echo echo something benign > 0a.sh
$ chmod 0700 0a.sh
$ *
something benign
$

Let’s see that again

$ set -xv
set -xv
+ set -xv
$ PATH=$PATH:$.
PATH=$PATH:.
+ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:.
$ echo echo something benign > 0a.sh
echo echo something benign > 0a.sh
+ echo echo something benign
$ chmod 0700 0a.sh
chmod 0700 0a.sh
+ chmod 0700 0a.sh
$ *
*
+ 0a.sh bin boot dev etc home lib lost+found mnt opt proc root sbin tmp usr var
something benign
$

Notice how 0a.sh was executed as it was the first file in the list, and this could be any executable in the directory because the command sorts the commands in alphabetical order and arbitrarily expands the expression and faithfully executes it, whatever it is, and here lieth the danger, amongst others like replacing system commands unwittingly.

Beware, an accidental * could launch all kinds of mischief!

Shell Tricks Part 1 – Substituting basename, dirname and ls commands

Substituting basename, dirname and ls commands

In Bourne shell, it is possible to use the following variable expansions as substitutes for the basename, dirname and ls commands

$ MYVAR=/path/to/basename
$ echo ${MYVAR##*/}
basename
$ MYVAR=/path/to/dirname
$ echo ${MYVAR%/*}
/path/to
$ echo *
bin boot dev etc home lib lost+found mnt opt proc root sbin tmp usr var
$

Hows That?

ICT in schools

I was reading about ICT in schools today, and pondered my past experience, i had a privileged experience but in many ways also a pretty crap experience of IT while at schools, so I thought to give my tuppence on the subject…..

My days of school ICT was spent on a BBC Master or an Acorn Archimedes. During this time I ‘learned’ about word processors, spreadsheets, and databases.  The Internet had not yet gained universal awareness and I was lucky enough to have a 386sx25 in 1991. By 1993, I was dialling-up HENSA at Lancaster University and BT Gold using my 2400 baud modem (gained when everyone else had 14.4k modems).

While I learned the basics of computer based ‘office-work’, they never taught me about computing. I got into a lot of trouble for my ‘shift-break’ naughtiness using my knowledge of basic to post infinite loops of questionable messages. The funniest being at 6th form and setting all the machines to say “Haroooooooooooon!” in honour of my mate was into computers and who’s name become the startup sound for all the machines! lol. I wouldn’t do that now, it’s too childish, but my it was funny at the time.

When I finally graduated from University, with a degree in software engineering, I realised what schools were missing. What I come to realise was that it was the maths which caused me to gain a greater understanding of the ‘universe’, not the ephemeral languages, and techonogies which all pass in fads over time, but what is universal behind all that is the math.

What is missing from school ICT isn’t so much the ‘raspberry-pi’, but it is an introduction to logic and formal proof. It is a given that we have general purpose machines which will allow us to model reality in a virtual sense in order to enact a real-world function. Simply teaching Microsoft Office isn’t enough.

I  recall thanking my uni maths teacher, Robert Lowe (Coventry University), as his teachings while ‘boring’ at the time, turned out to be the most useful knowledge I have ever possessed, simply knowing truth from non truth.

Children need to learn at an earlier age, base 2 math, binary. This is an important introduction into mathematical truth, the ‘proof’ being 1 or 0, true or false. While I don’t expect children to proof literary statements, it would be advantageous if they at least knew de-morgan’s law.

Once the student knows about logic and what a computer can do in terms of logic cases, then it becomes possible for the student to grasp the capabilities of the hardware and realise the software possibilities within realistic terms.

The other greater benefit is the introduction of what is truth, what is false, and most importantly the differentiation of  one-way truths. This enables the student with a soft-skill knowledge which allows them to differentiate the truth better, and that enables better decision making in all future cases as a sense of truth is universal.

It turns out that the truth can indeed be calculated mathematically. It is primarily for this reason that I believe that 15+ year olds should be exposed to binary and logic. A curriculum which includes addition, multiplication, division, and subtraction for the advanced. It should conclude in de-morgan’s law and a light introduction to finite-state automata for the advanced (e.g. a ‘traffic-light’ system). I don’t believe that these concepts are beyond the average teen-age person.

This would nurture an enlightened society by addressing the basic sense of logic and truth and this can only be good. While it may not seem creative for some, it is the foundation of creativity in an ever-evolving world.

I urge all science and maths teachers to embrace binary as a fundamental concept for teenagers wordwide.

If you know someone involved with school maths, science, or ICT – show them this post! – there’s more to computing than office apps!

Real Security: A GravityLight in the darkness

Guys and Gals,

Today I present to you something far more important than dealing with a technology disaster. The need for light and energy.

Everyone should get behind this project:-

GravityLight

http://www.indiegogo.com/projects/282006

These guys have developed an amazing product! a light which works on gravity alone!, while not a completely novel concept, these guys have packaged it into something portable, simple and hopefully reliable.

Intended for developing countries to reduce dependence on relatively expensive and unhealthy kerosene lamps, it represents an essential survival tool for all because when the candles have all burned out and the batteries are all flat, having some light source can be essential.

Give them some ca$h and help them on their way.

AV Comparatives

Today, let me introduce you to AV Comparatives, a trusty AV testing lab which will open your eyes to how good your anti-virus is. I have used these guys for many years to consider my options on AV.

Disclaimer: Don’t be fooled by the sell of McAfee and Symantec – they are *NOT* the best AV products by a country mile.

The reports from AV Comparatives shows the difference between “out-of-the-box” and “configured-for-security” effectiveness. This provides an interesting and sometimes scary revelation.

Please pay special attention to the historical reviews for proactive tests. The teams that score best consistently on this test do better overall because if they are on-top for 0day threats then the historical virus detection is, as they say, “history”. You can see developer drain happen when a product slips from it’s ranking where a developer leaves or the company generally lags.

For Windows, I normally use Avira Free with secure-start and detection of all categories including jokes and games. Just taking another look, I guess I might reconsider…..maybe Avast?

I’d like to try QiHoo but I can’t read Chinese and I’m not sure i trust a ‘free’ product which is difficult to find on Google and intended for a single-country only market (you can’t even find it easily on Baidu!). Chinese users – please leave comment on this point and let me know what your experience with QiHoo AV is like!

Meanwhile, I’m on Linux, so ClamAV will do for now.

Hidden H4x0r theme in Microsoft Windows!

Probably my most pointless and most worthless post of mine in a while but…

While messing around with themes in Windows 7 today, I found “High Contrast #2”, which is by any statement a ready made h4x0r theme with more akin to green-screen uber-dark geekdom them any plausible readability concept.

Bizarre but true! Try it!

Update: I have found that the theme is present right back to 3.1 lol!