Wednesday 23 November 2011

rename many files...

for i in `ls -l | grep -i billund|grep -v flat|awk {'print $9'}`; do (mv $i `echo $i|sed -e "s/billund/ongar/g"`); done;

replace string 'billund' with 'ongar'
for i in `ls -l | grep -i ongar|grep -v flat|awk {'print $9'}`; do (cat $i |sed -e "s/billund/ongar/g" > $i.new);done

move 'new' files into place of 'old' files
for i in `ls -l *.new|awk {'print $9'}`; do (mv $i `echo $i|sed -e "s/.new//g"`);done;

tune2fs -O ^has_journal /dev/sda1

Ghetto cloning of an ESXi guest... Probably not the most elegant method. This clones the host 'billund' to a new host 'markyate'

  1. Power down the guest.
  2. ssh to the host... assuming you have tech support mode enabled (see here) 
  3. cd /vmfs/volumes/{name of the datastore}/
    e.g.  cd /vmfs/volumes/SATA1/
  4. Copy the raw files (this always longer than you want):
  • cp -r {folder containing guest to be cloned} {name of folder to contain new guest}
    (e.g. cp -r billund.contoso.internal markyate.contoso.internal)

use sed to rename each of the files in the directory (I know there's probably a better way)
  • for i in `ls -l | grep -i billund|awk {'print $9'}`; do (mv $i `echo $i|sed -e "s/billund/markyate/g"`);done

use sed to update the paths in each file (that isn't a disk) to reflect the new name
for i in `ls -l | grep -i ongar|grep -v flat|awk {'print $9'}`; do (sed -e "s/billund/ongar/g" $i > $i); done;

Monday 11 July 2011

Clearing out the old mail queue

Never got the hang of executing stuff from inside awk until now... this searches all the queued mail for a specific string that we think we can discard, then calls rm with the filename. not pretty or clever but functional.

grep /opt/zimbra/libexec/zmqueuelog *|awk -F \: '{system("rm " $1)}'

Saturday 14 May 2011

iPlayer - Linux - Downloads keep pausing

Linux machine (Fedora 14 x86), missed Dr. Who, so I install the new iPlayer desktop, as you do.

Fist of all, I couldn't get the desktop app to start at all, but I found that if I disabled selinux things worked a little bit better. I have a permaent issue with flash/air and selinux so it's ot a surprise. Fire off setroubleshootd andget the string I need to build the selinux policy...

>grep 4242432069506C6179657220446573 /var/log/audit/audit.log | audit2allow -M iPlayer
>semodule -i iPlayer.pp

Once done, with selinux back up and running, I can then choose the link and my download queues OK from my browser. Next hurdle; when I start the download, it thinks for a bit then pauses. Try to start the download and it pauses again. Repeats several times...
 
I found my iPlayer.log under my home directory, specifically:
~/.appdata/BBCiPlayerDesktop.61DB7A798358575D6A969CCD73DDBBD723A6DA9D.1/Local Store/iPlayer.log

I had to use 'locate layer.log' to find this - I've got to say I'd be inclined to use a symlink to the log in an easy-to-find place...

Tailing the log shows:

5/14/2011 22:20:11.177 [ERROR] uk.co.bbc.BOMFileUtils Error reading bom. Error #2006 (in file '/home/barry/nfs/video/iPlayer/repository/b01187dm/b01187dm_hi_208047119.part)'
5/14/2011 22:20:23.885 [INFO] uk.co.bbc.LicenceManager Getting licence for //home/barry/nfs/video/iPlayer/repository/b01187dm/b01187dm_hi_208047119.part
5/14/2011 22:20:24.619 [ERROR] uk.co.bbc.ContentItemsProxy LicenceError:3313
5/14/2011 22:20:24.620 [ERROR] uk.co.bbc.LicenceManager Licence failed. The voucher associated with the encrypted content could not be saved to Microsafe. ErrorId: 3313. SuberrorId: 4353.

this repeats each time the download starts.

Because I play about with stuff a lot and can be careless, I have a redirection of most of my home directory to a snapshotted NFS mount - I'd just set this up and this was owned by 'nobody'. I set ownership of the parent directory to my account on the far end ("chown barry:barry /WD1/barry/nfs")... restart the download and suddenly everyone's happy.

Thursday 28 April 2011

vCenter server on Server 2008 R2 - hosts marked as "Disconnected" after 90 seconds

A bit of an oddity...

For convenience, I installed our current vCenter cluster in our dev lab. This meant an isolated network, with a simulated default gateway (for ESXi's heartbeats). Installed everything, up and running, no problem. Slight issue when putting the system into service though; I fired up the ESXi hosts, started the vCenter server, activated windows, joined to the domain, rebooted... when the machine came back up, I could connect to vCenter, but the hosts wer marked as 'Disconnected'. H'm. A bit odd but OK then... Right-click the host, choose 'Connect'... and all is well. start digging about getting the thing into service and suddenly the host falls off. I can connect directly to the host and everything seems well there, a cursory chceck of the logs seems to be OK.
Repeat this process a couple of times until it gets boring. Reconnect the host, and after a short timne the host falls off again. A quick check of the VMware KB brings me to this:
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003409

so I follow this through and come across a note in this KB article...
http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&externalId=1008030

"Note: The host goes into the Not Responding mode for a default 90 seconds time after adding it to vCenter Server. In case the vCenter Server is multi-homed, verify that the internal IP (that is reachable by the ESX hosts) is set as the management IP."

90 seconds is exactly the amount of time I get before the host falls off again. OK, so it's specifically a comms issue between the host and the vCenter server... a vmkping bears this out - I can ping the host from the vCenter server but not vice versa. OK, that sounds like a firewall isssue...

Turn on firewall logging on the vCenter server...

On the vCenter server, open Windows Firewall (which has changed a bit since I was a lad) and modify the logging fields - right click "Windows Firewall with advanced security" (the parent object) choose 'Properties', 'customise' the 'logging' field, increase the size to maximum (32KB), and set 'log dropped packets' to 'yes'.

open cmd and:
cd %systemroot%\system32\LogFiles\Firewall
type pfirewall.log

note a spot of DROP for TCP 902 - that's the inbound heartbeat from the host, which explains the behaviour... the R2 server is dropping traffic from it's hosts. It can establish a session because that's outbound and, well, established traffic. But unsolicited inbound stuff from hosts is broked. But R2 is a supported OS. So what happened?

We're joined to an AD domain, so have a look at the inbound firewall rules for the domain profile... well, there's a bunch of stuff specified by the vCenter server install, but it's all in the 'Private' profile... because that's where we were when the install was run. Since I joined to the domain, the firewall profile changed, and the rules the installer set up are no lomnger valid. Pretty easy to fix... select each rule that starts "VMware vCenter..." and make sure it has the 'Domain' profile ticked on the 'Advanced' tab. Immediately the hosts start talking to me again...

so really this occurred because of the shortcut I took of installing vCenter on a workgroup member then changing to a domain profile...

Tuesday 28 September 2010

I am Barry's secret junglist shame

OK, on paper I'm a bit... old for belgian techno/drum'n'bass/jungle.

But, it's a good thing that's gone from strength to strength. If you're going to make atonal noise with too much drum and not much else, make it LOUD atonal noise with too much drum and not much else.

To quote an old friend, "sometimes it's no good unless it makes your socks vibrate inside your shoes".

Jungle Train

Reporting ESX datastore usage

The NAS that our datastores are held on don't understand the vmfs disk format, and report that the LUNs are near full when they aren't - just I've touched over 90% of sectors at some point. The below is scheduled as a weekly report and reports usage in total to a CSV file and datastores over 75% used in the message body. I'm going to use the HTML conversion routine a lot more now, it's miles better than attaching CSV files - here's to uglier looking emails..

+===============================================+

add-pssnapin VMware.VimAutomation.Core #see? useful already.

$myVCServer="myvcsvr.example.com"

$mySMTPServer = "smtp.example.com"

#munge a date-time and report filename together
$now=get-date -format "MMM-dd_hhhh-mm-ss"
$filename = "d:\temp\diskusage_" + $now + ".csv"
$htmlfilename = "d:\temp\diskusage_" + $now + ".html"
#probably this is redundant
$file=$filename

#connect
connect-viserver $myVCServer

#get our snapshot list
$report=get-datastore|select-object Name, FreeSpaceMB, CapacityMB, @{Name="PctUsed";expression={[math]::Round(100-(100/$_.CapacityMB)*$_.FreeSpaceMB)}} | sort-object -property PctUsed
$report | export-csv $filename -NoTypeInformation
$summary=$report|where-object {$_.PctUsed -ge 75}
$summary|convertto-html|out-file $htmlfilename

$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($file)
$smtp = new-object Net.Mail.SmtpClient($mySMTPServer)
#mail the file out
$msg.From = "helpdesk@example.com"
#$msg.To.Add("admin@example.com")
$msg.To.Add("helpdesk@example.com")
$msg.To.Add("barry@example.com")
$msg.Subject = "ESX environment - Disk utilisation"
#$msg.Body = "Utilisation of each datastore, generated $now`n"
#$msg.Body = $msg.Body + "This report runs weekly from $myVCServer.`n"
#$msg.Body = $msg.Body + "Full report attached.`n`n`nDisks greater than 75% usage:`n"
#$msg.Body = $msg.Body + {$report|select-object Name, PctUsed|where-object {$_.PctUsed -ge 75}}
$mycontent=get-content $htmlfilename
$msg.body = $mycontent
$msg.Attachments.Add($att)
$msg.IsBodyHTML = $true
$smtp.Send($msg)
$att.Dispose()

+===============================================+