Labels

Friday, August 23, 2013

Find duplicates in bash


find_dupes.sh


 #! /bin/bash
OUTF=rem-duplicates.sh;
echo "#! /bin/sh" > $OUTF;
echo ""                >> $OUTF;
find "$@" -type f -print0 | xargs -0 -n1 md5sum | sort --key=1,32 | uniq -w 32 -d --all-repeated=separate | sed -r 's/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-])/\\\1/g;s/(.+)/#rm \1/' >> $OUTF;
chmod a+x $OUTF

Run the script:
./find_dupes.sh /path/to/check .\

Which will output a file called rem-duplicates.sh which can then be edited as you wish.

I stole this from here. Credit to , who in turn used code from J. Elonen


LED lights on my Vespa

Thursday, August 15, 2013

Wednesday, August 14, 2013

How to setup a reverse ssh tunnel

Ever wanted to know how you can ssh into your work desktop/server? Well do not worry any longer.....
    • All you need to do is create a reverse tunnel from your Work Desktop/Server to your home server.

    • ssh -nNT -R 5000:local_server:22 username@remote_server
    • Now from the remote_server run this
      ssh -p5000 localhost.... now we are in our work desktop/server.
    • Lets brake this down a bit..

    • The -n option Redirects stdin from /dev/null. This must be used when ssh is run in the background.
    • The -N option does not execute a remote command. This is useful for just forwarding ports.
    • The -T option disables pseudo-tty allocation.
    • The -R option does tha job of setting up the reverse tunnel.
    • Port 5000 is the port that will be listening on the remote_server (this can be any random port over 1024, if you want to run this as a non-root user).
    • local_server is the desktop/server that you are creating the connection from.
    • Port 22 is the port that you are making the ssh connection to.
    • user_name@remote_server is where you are making the ssh connection to for the reverse tunnel.
    • We need to make sure we keep this connection open.
    • In /etc/ssh/sshd_config we need to make sure this is set TCPKeepAlive yes.\


This page was stolen from somewhere else, I can't remember where. Sorry to the original author..

Running a script as root

The problem:

In theory, running a script as it's owner (in our case root) is simple, all you have to do is set the 'setuid' bit (sometimes mistakenly called the 'sticky' bit) by using 'chmod 4755' (or chmod 4***, depending on what mode you need). The problem is, that the 'setuid' bit functionality has been disabed on most Linux based distros for security reasons. This affects only scripts, not compiled code which should still work.

Solutions:

binary wrapper

The 'setuid' bit still works for compiled files. So what you can do is write a little c wrapper that will execute the script you want to run as root.
#include 
#include 
#include 
#include 

using namespace std;

int main(int argc, char* argv[]) {
    setuid( 0 );
    string cmd = "/opt/local/cmd.sh";
    for (int i = 1; i < argc; i++) {
        string arg (argv[i]);
        cmd += " ";
        cmd += arg;
    }
    int exitcode;
    exitcode = system(cmd.c_str());
    return WEXITSTATUS(exitcode);
}

Safe this as 'runscript.c', then compile and do the following:
gcc runscript.c -o runscript
sudo chown root:root runscript
sudo chmod 4750 runscript
You should now be able to run this command as root.

sudo wrapper

Add the following line to your sudoers file, with 'group' being the group you want to give access to your script.
group    ALL = NOPASSWD: /path/to/script
Then write a wrapper, executing you script with sudo.
sudo /path/to/script
Also your script will have to perform a 'setuid(0)' to make sure that all child processes are executed as root.

A couple of things to note:

  • it's not enough to do 'chmod 4***' on the binary, you also have to use 'setuid' inside the code.
  • an additional problem on Mac OS X is, that by default the 'setuid' bit is disabled on NFS mounts.


x forward session with xdmcp

XDMCP allows logging into a remote host, but displaying the desktop on your own host.
1) edit /etc.gdm/custom.conf
[xdmcp]
Enable=true

[security]
DisallowTCP=false
AllowRemoteRoot=true
2) restart X (telinit 3; telinit 5)
3) login as root and run:
gdmsetup
4) On the remote tab, change 'style' to 'same as local'
5) On the security tab, tick 'allow local system administrator login' and 'allow local system administrator login'
6) restart X

To test, log off your host, and press F10 in the login GDM login window. You can enter the name of the remote host to login too here.

Forward user x sessions

When logging into a remote host as root, you lose the ability to forward x sessions after an su to another user.
To allow x-forwarding after you perform an su, you need to request the cookie for the current server:

ssh root@somehost

xauth list
returns:
 somehost.somedomain/unix:10  MIT-MAGIC-COOKIE-1  d9fc3512df83a70ea8054dff21f58e28

Now, su to the user:
 
su - someuser

xauth add somehost.somedomain/unix:10  MIT-MAGIC-COOKIE-1  d9fc3512df83a70ea8054dff21f58e28
now x apps will forward correctly - test with xterm.

Friday, July 26, 2013

20MB Boot Floppy Image

These days BIOS and IPMI (and other no doubt) updates are getting larger.

Most of the boot floppies you can download are 1.4MB which makes upgrading some firmware modules difficult when PXE booting as the images wont fit.

I was able to build a 20MB image using these commands.

wget http://itblog.su/downloads/W98SE_R.img
rpm -ivh ms-sys-2.2.0-1.el5.rf.i386.rpm
dd if=/dev/zero of=floppy.img bs=1024 count=20000
mkdosfs floppy.img
ms-sys -1 -f floppy.img
mount -o loop floppy.img /mnt/floppy
mount /W98SE_R.img /mnt/dos
cp /mnt/dos/* /mnt/floppy/
umount /mnt/dos/

IPMI Upgrade through PXE

The Supermicro nodes have IPMI modules built in. These can be accessed using either the dedicated IPMI NIC, or by sharing the primary NIC with the host OS. We have chosen to use the shared option to reduce cabling.

Out of the box the machines came with a version of IPMI that didn't work for us so we had to update the IMPI firmware using the yafukcs utility.

The standard approach is to perform this via USB key but due to the number of nodes this is not practical. Therefore I created a freedos image containing the required firmware and configuration files that can be PXE booted to the nodes in one go.

This process saves around 4 days of manual labour. We still have to manually gather the MAC addresses of the new IPMI interfaces and add them to DHCP, but there are ways we can speed this process up using FDB in the switches.

Once we have our bootable image we add the required firmware update files

autoexec.bat
@echo off set PATH=.;\;\LOCALE
echo Using US-English keyboard with US-English codepage [437]
ipmicfg.exe -m
1.bat
2.bat
fdapm coldboot 

1.bat
yafukcs.exe -full X8DTT_~1.IMA 

Although it was quicker to update only the required modules using the -auto option we had better success with re-updating all the modules using the -full option.

2.bat
ipmicfg.exe -m
ipmicfg.exe -dhcp on
ipmicfg.exe -dhcp
ipmicfg.exe -r 

Once we run the update we configure IPMI with ipmicfg.exe to DHCP and very importantly perform a BMC cold reset. Then we add the image to the PXE config on our boot server (puppet in this case)

The relevant lines in the /var/lib/tftpboot/pxelinux.cfg/

LABEL Supermicro IPMI Firmware Update
KERNEL /sysresccd/isolinux/memdisk
APPEND initrd=/sysresccd/isolinux/floppy.img 

And copy the image (floppy.img) to /var/lib/tftpboot/sysresccd/isolinux/

We can now boot into the new image to ensure it works by selecting the new menu option from the PXE boot menu.

Sunday, January 23, 2011

CCOMTB - 2011 - Round 1

Status: Finished
Grade: B

What a race, and what a turn out! It looked like there were about 15 people in A grade alone. Great Nobmob turn out too, hopefully those that haven't been before can see what a great race it is and will attend some more. Well done to Ray for what looked like 5th place in A grade - what a demon. Logan, hope your cuts heal OK, they looked pretty nasty but nothing a pommy victory at the cricket wouldn't solve eh? Eye-wink

I started at the back of the pack in B grade, and had great fun once I decided to back the first lap pace off a bit. No idea what place I came, Gazza said I came in after him but I can't see how, I felt like I was pretty coozie on the last 2 laps. I was expecting to blow up hard given that I've been zero training since the new little man was born (who has great quad development at 7 weeks old incidentally) but I felt in pretty good shape. I had a chance to ride behind a 29er for some of it, those bikes certainly seem to make sense at a track like Ourimbah, he was certainly rolling over the rough stuff and making it look easy.

No events really.. big traffic jam at the top of the drop on the first lap, looks like someone didn't ride the lap before hand Sticking out tongue, I lost the rear end on Small meadows, I couldn't get rid of the smile in the grave yard, oh and I loved the end of the the roller coaster now that it misses magic carpet. It sounds like magic carpet is about to get some pretty choice upgrades - can't wait for round 2.

Thursday, December 23, 2010

CCOMTB - 2010 final results

For my record keeping, the final results have been posted up:

Final results : http://www.ccomtb.com.au/results/Final%20XC%20Rankings%202010.pdf

What a great year, never thought I could get first place in B grade, but I guess showing up to as many races as possible really pays off. I'm really going to try and do some next year as well.

Edit: Managed to get to the first round of CCOMTB XC 2011, and picked up my trophy Laughing out loud

Monday, November 01, 2010

CCOMTB - Club Race - 2010 Round 10 - 6 hour Final

Status:
Finished
Laps:
9
Time:
06:20:16
Position (Overall):
8

Hard. Phew, what a race.

This was my last for a while with a baby on the way my races are taking a back seat. This was also the last race of the CCOMTB season and I managed to do all but one so wanted to go well. I started too hard after telling eveyone I was going to go easy and realised I was in for a hard race by the end of lap two. I just couldn't drink enough water and by lap 5 was showing the signs of dehydration. I pretty much had a rest after every lap from then on. Timing was good though, managed to time the cut off just after passing through the gate so squeezed another (very slow) lap in. On that lap I ran over a snake and narrowly avoided a rider coming the wrong way at the bottom of browns! The scare almost made me forget the cramps.

How some people do solo 8 hours around here I don't know.

The CCOMTB season has been great, recommended to everyone for good hard racing, friendly people and of course some of the best trails around.

Monday, September 13, 2010

CCOMTB - Club Race - 2010 Round 9 REVERSE LOOP

Status: Finished
Laps: 3
Race Category: B Grade Men

Great but hard race. Like a different track in reverse, but really good fun, and some big hucks. Still waiting for the result but I'm told I was 3rd or 4th.

http://connect.garmin.com/activity/48763936

Wednesday, August 25, 2010

CCOMTB - Club Race - 2010 Round 8

Status:Finished
Laps: 3
Time: 01:45:07
Race Category: B Grade Men
Position (Category): 4

Great race this weekend. Come on Gazza, the championship's yours to loose now.