Monday, 10 April 2017

simple bash 'logrotate'

'logrotate' = not a logrotate but more of a multiple result handle
e.g. test results, core files, log files

'infinate' (max bash integer) 'logrotate' pattern for bash:

    # multiple runs of same test, . . logrotate test result
    [[ -e dir/testresult_${testname}_${host}.xml ]] && {
        K=$(find dir/testresult_${testname}_*_${host}.xml 2>/dev/null |wc -l)
        mv dir/testresult_${testname}_{,${K}_}${host}.xml

Coupled with test harvest e.g. . . 
rsync -avzh --remove-source-files ${user}@${host}:XML/*${host}.xml ./ || true

optional || true so that lack of xml files doesn't mark job/script as fail

Sunday, 12 March 2017

Scout County Survivor - Air drop Token hunt challenge

3 rock Scout County
Survivor Token Map Challenge

An aircraft has been heard flying overhead. Your team catch
a brief glimpse of the aircraft through storm clouds. It is being
severely buffeted by strong winds. You see multiple things
are dropped. Some items fall quickly, other items blow in the
wind. Shortly afterwards some leaflets are seen floating down
from the sky.

The leaflets say:

Dear Survivors,

Please be assured help is on the way. We hope that rescue
teams will reach you in approx. 24 hours.
Due to rough terrain and poor visibility we have had difficulty
pinpointing your location from the air. Supplies have been
dropped at several locations that we think you may be able to
reach. Please see approximate locations of drops on the

to survive independantly until rescue!

(IN REAL LIFE: Look for triangular survivor tokens. You should retrieve the token, bring it to Scout Leaders Area and redeem it for items recovered from supply drop cache.)

PDF and Inkscape SVGZ TOKENS: Food, Shelter, Fire, First Aid

Tuesday, 17 January 2017

weekend B(ullet?)Log, fix guitar, bike maintenance, photo sync, visit Limerick

 x repair Maeve's guitar using wood glue, leave for 48hrs

 - Drove down & back from Limerick. Met Eimear&Stephen&Aoife.
 x rsync'd photos james laptop -> USB drive
 x look for Maeve school photos -  found a few cute ones but not for sending to journal
 x Strung/tuned guitar. But as strings tightened glue stretched :-(

  x fix guitar with superglue
  x fix Kate bike one set brake pads replaced
  x fix Maeve bike brake squeal (brake cables oiled, tightened // front brake pads fully off and back on - nuts were in ok order // BALANCED each side of brakes front and back (spring adjusted screws both sides)
  x fix James bike disc brake pads (from Halfords) back brake was worn just down to metal, front brake less worn but replaced
  x fixed 3 bike tubes
  x Strung/tuned guitar. But as strings tightened glue stretched :-(

  x Strung/tuned guitar. But the superglue is not holding.
  x Repair guitar using glue + bracket. (cut the bracket)
  x Strung/tuned guitar. repair is holding.
  . guitar bracket flush, round bottom corner, hammer a curve in it
  - need a mini-anvil :)

  x morn: tuned guitar - it's starting to hold in tune ok, Maeve tested it

  x gave rationality.pdf Harry Potter to Kate/...
  . reading graphic novel last man Y

for Wed/future . . .
  . Glenmalure hike plan
  . scouts plan hike for Jan/Feb ?
  . scouts PLC . . long term plan . . adventures, skills, special interest, Survivor, County Cup
  . scouts Annual Camp plans
  . scouts County meetings/activities
  . scouts James leader training
  . Cycling submission: DART crossing/Booterstown
  . DLR fernhill submission

Looked @ Bullet Journal mechanics:

This blog acts as an occasional diary or article log for me.
I have a book for Scouts and work which is diary/planner journal.
I have often scrappy bits of paper with task lists or planning ideas.
Also task manager app, google calendar, gmail, .. .


Thursday, 3 November 2016

rsync from android MTP . . freezy/hangy problems. s/rsync/crude script/

Samsung Galaxy Nexus.
3.8G of photos in internal storage.
Options are MTP "mounting" or PTP.
Ubuntu 14.xx


First attempt copying using file manager . . . started out okay. Reported 3.8G will be copied over in 7 mins . . 15 mins . . later 1 hour and x mins. And it was getting stuck / hanging up (looked like at the same point).

Unplug/replug USB did not bring back MTP connection after hang. Needed to go to phone USB computer connection Settings and un-check and then re-check MTP to recover it.


cd /run/user/1000/gvfs/
cd mtp* # e.g. mtp::host=%5Busb%3A001%2C017%5D/
cd "Internal storage/DCIM"
rsync -avzhP ./ ~/Pictures/201611FionnOldMobilePhone/DCIM/
see errors like this:

          1.59M 100%    1.67MB/s    0:00:00 (xfr#1834, to-chk=957/2800)
          1.98M 100%    1.25MB/s    0:00:01 (xfr#1835, to-chk=956/2800)
rsync: read errors mapping "/run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C017%5D/Internal storage/DCIM/Camera/IMG_20130808_123846.jpg": No data available (61)
          1.43M 100%    1.57MB/s    0:00:00 (xfr#1836, to-chk=955/2800)
rsync: read errors mapping "/run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C017%5D/Internal storage/DCIM/Camera/IMG_20130808_123902.jpg": No data available (61)
          1.58M 100%    1.21MB/s    0:00:01 (xfr#1837, to-chk=954/2800)
rsync: read errors mapping "/run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C017%5D/Internal storage/DCIM/Camera/IMG_20130808_124320.jpg": No data available (61)
          1.54M 100%    2.00MB/s    0:00:00 (xfr#1838, to-chk=953/2800)
rsync: read errors mapping "/run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C017%5D/Internal storage/DCIM/Camera/IMG_20130808_124435.jpg": No data available (61)
          1.90M 100%    1.54MB/s    0:00:01 (xfr#1839, to-chk=952/2800)
rsync: read errors mapping "/run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C017%5D/Internal storage/DCIM/Camera/IMG_20130808_124530.jpg": No data available (61)
         32.77K   1%  126.98kB/s    0:00:17 
. . restarted . .
. . stuck again . . 

. . seemed to be getting stuck on the same files . . 
These errors seem to be encountered if rsyncing from files which get changed while sync happens.  I think android should not be changing them. I don't think MTP would expose corrupt disk problem ? Something like antivirus locking the files should not be problem. Anyway, MTP connection a bit flaky . . maybe something on the android side is locking files or MTP drivers are a bit funny.
Tried rsync with --remove-source-files on whole and on file selections (e.g. Camera/IMG_201606*) still got stuck. Each time after hang needed to go into droid unselect MTP and select again to connect again. At least files to be checked/transferred are being reduced now by removing them after they are synced.

    rsync -avzhP --remove-source-files ./ ~/Pictures/201611FionnOldMobilePhone/DCIM/

rsync was getting stuck on the same file all the time. cp seemed to have less of a hanging problem. more tolerant of read errors? So made a script to do copy and remove if copy successful.

    # Script using cp -p (and remove files as we go)
    cd /run/user/1000/gvfs/mtp*/Intern*/DCIM
    FILES=$(ls Camera/)
    for f in $FILES; do echo -n $f; cp -p Camera/$f $DEST/ && rm Camera/$f && echo success; done

This was run in a while true loop periodically recovering MTP connection when it hung.
      while true; do ~/bin/; sleep 1; done

The script saw some funny errors e.g. :
    IMG_20130815_145455.jpgcp: error reading ‘Camera/IMG_20130815_145455.jpg’: Input/output error
    cp: failed to extend ‘/home/jamesc/Pictures/201611FionnOldMobilePhone/DCIM/Camera/IMG_20130815_145455.jpg’: Input/output error
    . . .

And it would hang . . . periodically recovered MTP connection as already described.
The script evolved . . . 

    Binary files Camera/IMG_20160104_095626.jpg and /home/jamesc/Pictures/201611FionnOldMobilePhone/DCIM/Camera//IMG_20160104_095626.jpg differ

cd /run/user/1000/gvfs/mtp*/Intern*/DCIM
FILES=$(ls Camera/)
ls Camera/ |wc -l
for f in $FILES; do
   echo -n $f;
   if [[ ! -e $DEST/$f ]]; then
      # the timeout doesn't work on frozen mtp file
             # we run this full script in a while true; do ~/bin/; sleep 1; done loop
             # and periodically visit, if stuck unlock phone, deselect MTP and select it again
             # (to interrupt and restart MTP connection)
             # simply unplug & replug doesn't bring MTP connection back ok
      timeout 20s cp -p Camera/$f $DEST/ && rm Camera/$f && echo success;
      echo already done by earlier script which did not tidy up;
      diff -u Camera/$f $DEST/$f
      if [[ $? == 0 ]]; then
         rm Camera/$f && echo RM
         # doing this copy on the weird files causes nasty freezy freezes.
         #cp -p Camera/$f $DEST/$f && rm Camera/$f && echo success;
                # ALOT of files found to be a few bytes different.
                # another copy caused hanging . . . so if dest file kindof looks ok we just remove source
         identify $DEST/$f && rm Camera/$f && echo RM


    # a few bytes in size different
    ls -al Camera/IMG_20150117_171621.jpg $DEST/Camera/IMG_20150117_171621.jpg
      -rw------- 1 jamesc jamesc 1277901 Jan 17  2015 Camera/IMG_20150117_171621.jpg
      -rwxr----- 1 jamesc jamesc 1275306 Nov  3 01:09 $DEST/Camera/IMG_20150117_171621.jpg
    # copy again ? results in same size difference, date/time fixed up though
    cp -p Camera/IMG_20150117_171621.jpg $DEST/Camera/IMG_20150117_171621.jpg
    ls -al Camera/IMG_20150117_171621.jpg $DEST/Camera/IMG_20150117_171621.jpg
      -rw------- 1 jamesc jamesc 1277901 Jan 17  2015 Camera/IMG_20150117_171621.jpg
      -rw------- 1 jamesc jamesc 1275306 Jan 17  2015 $DEST/Camera/IMG_20150117_171621.jpg
    diff -u Camera/IMG_20150117_171621.jpg $DEST/Camera/IMG_20150117_171621.jpg
      Binary files Camera/IMG_20150117_171621.jpg and $DEST/Camera/IMG_20150117_171621.jpg differ

So EVENTUALLY by removing files we had already copied we had less and less to do and got through all files. Phew. And yay.

    du -h $DEST/.. --max-depth=0
      3.6G    /home/jamesc/Pictures/201611FionnOldMobilePhone/DCIM/Camera//..

Various other reading . . . 

Tuesday, 18 October 2016

char c; int i; c[&i]; // index a simple var using pointer in c compiles (and runs often without segfault)

    char c;
    int i;
    //printf("%02x",c[i]); // doesn't compile, error, cannot access c as array
    // "error: subscripted value is neither array nor pointer nor vector"

c[&i] there is SOOOO BAD and WROOONG. Semantically wrong. But apparently not syntactically wrong in c.

Why does it compile?
Because 1. array[i] == *(array+i) == *(i+array) == i[array]
And 2. c casts char to int happily

In case of c[&i] c is the index added to pointer &i.
Now &i + value of c indexes an undefined area of memory so it is not good to use this!!

    char c;
    int i[10];
    // normal access into array (bad to use a char as array index though)
    for(c=0;c<10;c++) printf("%02x",i[c]); // normal-ish
    for(c=0;c<10;c++) printf("%02x",*(i+c)); // equivalent pointer arithmetic
    for(c=0;c<10;c++) printf("%02x",*(c+i)); // equivalent
    for(c=0;c<10;c++) printf("%02x",c[i]);    // allowed BUT NOT NORMAL

    char c;
    int i;
    int buffer[20]; // buffer helps prog not seg fault!
    // abnormal access into memory at offset of (int)c from &i
    //for(c=0;c<10;c++) printf("%02x",&i[c]); // COMPILE ERROR
    for(c=0;c<10;c++) printf("%02x",*(&i+c)); // a bit weird
    for(c=0;c<10;c++) printf("%02x",*(c+&i)); // not normal
    for(c=0;c<10;c++) printf("%02x",c[&i]);    // but it compiles and runs(mostly)

    for(c=0;c<10;c++) printf("%02x,",i[&c]); // this is all
    printf(" ");
    for(c=0;c<10;c++) printf("%02x,",*(i+&c)); // a bit weird
    printf(" ");
    for(c=0;c<10;c++) printf("%02x,",*(&c+i)); // not normal
    //for(c=0;c<10;c++) printf("%02x,",&c[i]);    // COMPILE ERROR

While answering this question:

Asked this question:

Monday, 26 September 2016

Reset Windows 7 Administrator account (or any user account) password

Had some fun on Sunday trying to get access to Admin account on Windows 7 laptop. 
I attempted some other methods but what eventually worked for me was a bit of a hack/trick. Replace sethc.exe (sticky keys) with cmd.exe and trigger sticky keys (sticky keys is run as Administrator). This was done through using Notepad.exe which is run to view logfiles after system recovery. Other techniques to get in on command-line as admin with drive mounted didn't work. This trick is at least quite amusing :-) also simple and portable :-D. 
Background: The Administrator password with laptop was not known. There was a user account with admin privs so users didn't find the need of it. UNTIL the windows login page stopped showing their user! We are guessing the User profile became corrupt or had something bad in it.
I attempted a series of procedures before getting the Notepad+sticky keys replace hack to work. For the record here they are (and the problem I encountered with them):
  1. When trying to log in as Administrator after an incorrect password you are prompted to insert rescue disk (in order to reset password). We had a Windows 7 rescue disk on cd. But the prompt asked for floppy or USB. I had no handy USB stick and was too lazy to go shopping and messing with creating USB boot disk.
  2. Using system repair disk to get in on command-line did not allow the replacing of sethc.exe with cmd.exe trick/hack. Or allow resetting admin password 'net use Administrator *'. The command-line was running as admin but not as the real admin on machine more as the system repair admin and the disk did not seem to be mounted with full access . . . ~ not sure ~
  3. Using linux system rescue cd ( (version 4.8.2)) I could not mount the drive. I would kindof see it was a GPT partitioned drive - tools ntfs-3g gparted sfdisk should work with GPT but didn't. This computer has a prompt for username + domain + password before windows starts so not sure but maybe there is some extra security (which is needed to mount drive?)
  4. We looked at recovering the User Profile - editing registry - but . . . 
What eventually DID work was follow system recover sequence (no external/additional cd needed) at end view logfile (opens in Notepad). Then do file open - browse to cmd.exe - copy - paste - overwrite sethc.exe. Then reboot - trigger sticky keys - set password using command-line 'net user Administrator *'.
  1. Shutdown and reboot. When Windows starting is seen hold down the power button and power off.
  2. Power on. Windows boot should report that last Windows start up failed so it will give the option of "Launch startup repair". Choose this option.
  3. Cancel the Startup Repair. Cancel the System Restore.
  4. A report dialog will show reporting repair could not be done. In there expand "View problem details". Under problem details a link to x:/windows/... log file is shown. Click on this.
  5. Notepad.exe opens showing the logfile. This Notepad is running as Administrator and the mounted filesystem x: is your hard disk.
    5.1 Notepad: File - Open - browse to X:/Windows/system32 - scroll to sethc.exe
    5.2 Right-click on sethc.exe and rename to sethc-BACKUP.exe
    5.3 Scroll to cmd.exe. Right-click on cmd.exe. Copy. Right click. Paste.
    5.4. When I pasted cmd.exe the command-line ran (as Administrator) so I did 'cd x:/Windows/system32' and then 'copy cmd.exe sethc.exe' on command-line.
    5.4-1 If you prefer not command-line then just use Notepad File Open browser and make a copy of cmd.exe and rename it to sethc.exe
  6. Reboot without any funny stuff.
  7. At login page hit shift key 5 times or more triggering sticky keys. Instead of sticky keys prompt a command-line dialog appears. Running as Administrator. 'net user Administrator *' to set the password.
Good description with screenshots of the procedure here:

The rsync of old user to new user after successful recover. And a game of blockus :-)

In conclusion, this solution doesn't require you to have any extra boot or repair CD. It is very portable :-) It is pretty simple. So it is probably worth trying as one of the first password recovery methods.
We finished up Sunday with making a new user, failing to copy files from old user -> new user using windows, installing cygwin with rsync, rsyncing from old user -> new user (-avzhP and excluding ntdata files and a few other). Then backing up stuff generally. Took ages (3/4hours?) but successful recover at the end, phew.

Saturday, 24 September 2016

Recipe: Mackerel with spinach and apple

Recipe: Mackerel with spinach and apple

As usual winging it in the kitchen. Successful and tasty soup and fish for tea today.
The selection of ingredients depends often on what is there, what needs to be used.

Apple baked with the mackerel was a nice combination. James & Fionnuala and the girls liked it alot.

    2 plums
    2-3 tomatoes
    4 mushrooms (optional but good especially if you have a wife who loves them!)
    half a red onion
    mackerel - 3 fillets (Aldi's best)
    apple - tart(as in a bit sour) (my Mum and Dad brought some up from Cobh this Monday)
    spinach - we got a bag with the organic fruit & veg box
    oil, salt, pepper
    squeeze of lemon

   Turn on oven ~190 degrees.
   De-stone and slice plums, slice tomatoes, slice & dice onion, remove stalk from mushrooms.
   Put those in pyrex baking dish (some oil in first) and mix and put in oven.
   Shred/Chop some spinach - add spinach to dish in oven and mix in.
      (this was done a while after the rest baked a bit as I was making soup @ the same time).
   Add a small amount of lemon juice to dish in oven.
   Stir the dish in oven once or twice.
   Keep 3 large spinach leaves aside for the fish.

   Slice apple into wedges (quarter the apple, remove core/pips, slice).
   Take fish out of packet, rinse.
   Lay fish on a dish(I had it in a jug), season, put on oil, put apple on top.
   Squeeze on a small amount of lemon juice.
   13 mins to serving time put on the fish:
       Lay each fillet on a spinach leaf and lay wedges of apple on top.
       Lay side by side on top of the dish in oven.

   The apple stuck to top of mackerel and spinach stuck under.
   The spinach+fish+apple were easy to lift off and put on plate.
   Serve the mix underneath beside the fish.

We had soup with fish (and for he who didn't fancy fish):

Soup with 3 potatoes diced, half a butternut squash (deseeded but with skin) diced, 1 leek, 2 small carrots diced, some turmeric (the real root - small slices), grated ginger, chopped spinach, a black chilli pepper, a jug of vegetable broth(or stock), water, seasoning (salt, pepper, curry powder)
In that order (more or less) add ingredients and fry with oil first. Stirring frequently. If taking too long dicing and there is danger of burning then add some broth. You want to fry/broil the hard veg for a bit. I had broth from cooking potatoes + carrot + onion earlier in day. Add enough water at end to give a nice soup consistency not too thick. Spinach was added at end after heat was turned off.
After all cooked then buzz to smooth.

Serve with toast & butter.

Earlier on we had mash potato with black pudding, brocolli and eggs. (and some beans)

Mashed potato.
Potatoes roughly chopped. Carrot diced. Onion diced.
Boil potatoes with a small amount of salt in water. (some brine from an olive jar does nicely)
Add carrot and onion.
When potatoes  cooked (not soft/disentegrating) drain.
Keep the broth for making soup later.
Add some butter and a splash on milk.

Serve with black pudding, egg, brocolli stalk and head fried with turmeric.