SurlyJake Blog

Tar Extract Destination Folder

| Comments

Tar can redirect extracted files to a different folder. This can be handy if you want to unpack a tar archive stored on a cd or other read-only media and want to eliminate the step of first copying the archive, extracting it, then deleting the extra tar.  All you have to do is add a ‘-C ’ to the tar command.   So here’s an example using the VMware Tools tarball:

# tar -C /root -zxvf /media/cdrom0/VMwareTools-8.3.2-257589.tar.gz

This will redirect the extracted files into the /root folder. simple

Brasero, No Option for Creating ISO

| Comments

I love Brasero. It’s simple, lightweight, and comes with Ubuntu. Recently, when I wanted to back up a disk, ISO was not on the list of formats. As is usual, the issue was a missing package: brasero-cdrkit.

apt-get install brasero-cdrkit

Now, .ISO (ISO9960) will be an available disk format for you under Brasero.

<a href="http://www.surlyjake.com/wp-content/uploads/2011/01/Brasero-iso.jpg"><img src="http://www.surlyjake.com/wp-content/uploads/2011/01/Brasero-iso.jpg" title="Brasero-iso" height="520" width="552" alt="" class="alignnone size-full wp-image-690"></img></a>

Tandberg Endpoints Cannot Establish Calls Over Juniper Routers

| Comments

This is a nasty little issue. On my private network, suddenly some endpoints would refuse to establish calls made over SIP or H323. Error codes would be:

channel unacceptable
487 / Request Terminated
480 / Temporarily Not Available

Not particularly helpful information. After all the packet sniffing and diagnostic checks, it appeared packets were being rewritten or dropped between the endpoint and our VCS. The culprit here is Juniper’s ‘ALG’ for SIP and H323 traffic. I don’t have the time not to figure out exactly why or how it was breaking my calls, but i do know that in my case, it wasn’t needed. Disable the SIP and H323 ALG’s (in the SRX web UI under Configure –> security –> ALG. The endpoints will start working again after your reboot them and allow them to re-register to your gatekeeper.

More reading:

http://www.juniper.net/techpubs/software/junos-security/junos-security95/junos-security-swconfig-security/id-79332.html#id-79332

Monitoring Flexlm Usage With Zabbix

| Comments

Flexlm license usage can be a hard thing to accurately measure and monitor. Luckily, the output from lmutil can be used to display license usage. First thing to do is locate the lmutil binary and try to get it to run. I use Flexlm for autodesk on Windows and ESRI on linux(centOS).

Windows: This server seemed to want the license file specified. You may need to launch the lmtools GUI tool and watch the status bar for the path to it. This is what mine looked like:

"c:\program files\autodesk network license manager\lmutil" lmstat -c "c:\program files\autodesk network license manager\license\license.lic" -a

Linux:

/home/esri/arcgis/license10.0/bin/lmutil lmstat -a

That will spit out the current license usage for all your products. To isolate the numbers we want to monitor, we will be piping the output into some other commands like find and cut. I recommend using the GNU tools for windows http://gnuwin32.sourceforge.net/. These examples use the built-in ‘find’ utility, and a ‘cut.exe’ tool i found googling around. I had overlooked the gnutools when I first set this up. My mistake can be your gain. With gnutools, it will be easy to isolate the output you want using ‘grep’ and ‘cut’. First, isolate the line you are looking for with grep. You will have to figure out what feature code you want to monitor. mine looks like this:

Windows:

"c:\program files\autodesk network license manager\lmutil" lmstat -c "c:\program files\autodesk network license manager\license\license.lic" -a | find /i "64300acd_f:"

Linux:

/home/esri/arcgis/license10.0/bin/lmutil lmstat -a | grep ARC/INFO

now that you have the right line,  you can trim the extra characters with ‘cut’. It will take some experimentation to get it right.:

Windows:

"c:\program files\autodesk network license manager\lmutil" lmstat -c "c:\program files\autodesk network license manager\license\license.lic" -a | find /i "64300acd_f:" | cut -c 62-64

Linux:

/home/esri/arcgis/license10.0/bin/lmutil lmstat -a | grep ARC/INFO | cut -c 59-61

The output now should be only the number of licenses being used.

To allow zabbix to monitor this value, we need to create a ‘UserParameter’ read up on it here: http://www.zabbix.com/documentation/1.8/manual/config/user_parameters. This is what the parameter looks like on my servers:

Windows:

UserParameter=licenses.autocad.used,"c:\program files\autodesk network license manager\lmutil" lmstat -c "c:\program files\autodesk network license manager\license\license.lic" -a | find /i "64300acd_f:" | cut -c 62-64

Linux:

UserParameter=licenses.arcinfo.used,/home/esri/arcgis/license10.0/bin/lmutil lmstat -a | grep ARC/INFO | cut -c 59-61

Once you have the userparameter created on the license server, restart the agent and add an item in zabbix to begin collecting values.

View String Including Special Characters Like Newlines in Python

| Comments

After spending a frustrating hour or two trying to format a string, i stumbled on python’s repr() funcion. repr() allows you to inspect a string object when you’re troubleshooting your code. For example:

I was trying to understand a string that was shown in the terminal like this:

print mystring




Node - 192.168.1.104
ERROR:
Description = Generic failure

Seems pretty simple to remove the extra newline characters right? no. doing a string.replace(“\n”, “ ”) did not fix it, but actually mangled the string. So here comes repr() to the rescue…

print repr(mystring)




'Node - 192.168.1.104\r\r\nERROR:\r\r\nDescription = Generic failure\r\r\n'

\r\r\n… i’ve never heard of it before, but knowing that it’s there, i could easily change my replace to:

print mystring.replace("\r\r\n", " ")




Node - 192.168.1.104 ERROR: Description = Generic failure 

Pstools: Access Denied in a Domain Environment

| Comments

After upgrading to a windows 7 VM at work, I was having trouble getting pstools commands to authenticate on remote machines. After much trial and error, I realized some curious behaviour with psexec. Obviously, when connecting to a remote machine, I would try to use the ‘-u’ switch to specify my administrative account, but would always get ‘access is denied’. Of course, all of the normal things should be checked: simple sharing turned off, $ADMIN share working… you know…

The issue was apparently that if I log into my workstation as a non-administrative user, but try to issue pstools commands as an administrator,  it fails because Microsoft wants me to log into my workstation and work logged with my domain admin account.

Take a look at this example using psexec: On windows 7, running ‘cmd’ as your non-admin user, if you type in the command:

1
2
3
4
5
6
7
8
9
c:\Program Files (x86)\PsTools>psexec -u domain\domainadmin \\targetmachine cmd

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

Password:
Could not start PsExec service on targetmachine:
Access is denied.

If you:

  1. Hit start
  2. Type “cmd”
  3. Hold down ‘shift’ and right-click on the ‘cmd’ in the start menu
  4. Select ‘run as different user’.
  5. Type in your administrative credentials. Use the same ones you will use in the psexec command.

Now you should have your command line window open. If you run the same command as earlier:

1
2
3
4
5
6
7
8
9
10
11
c:\Program Files (x86)\PsTools>psexec -u domain\domainadmin \\targetmachine cmd

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

Password:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Windows\system32>

Now you’re in!

Ntpq Timed Out on freeBSD

| Comments

I was running ntpd locally on a server and wanted to check in on ntpd’s status. ntpq -p was not producing any output even though ntpd was running.

# ntpq -p
localhost: timed out, nothing received
***Request timed out

This is because I had the option “restrict default ignore” set in /etc/ntp.conf. ntpq. This makes ntpd ignore EVERYTHING, even queries to the loopback interface. Ntpq queries ntpd over the loopback interface at 127.0.0.1. To allow these local queries, add:

 restrict 127.0.0.1

to /etc/ntp.conf, then also add restrict lines for your other upstream ntp servers.

restart ntpd:

/etc/rc.d/ntpd restart

Now ntpq -p will show you status of it’s peers

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 dns3.untangle.c .INIT.          16 u    -   64    0    0.000    0.000   0.000
 mirror          .INIT.          16 u    -   64    0    0.000    0.000   0.000
 153.16.4.133    .INIT.          16 u    -   64    0    0.000    0.000   0.000

Cannot Delete ZFS Snapshot

| Comments

While Deleting to delete a snapshot, i typed:

zpool destroy zfsdiskpool@Sat

and got:

cannot open 'zfsdiskpool@Sat': invalid character '@' in pool name

This is because to delete snapshots in ZFS, you should use ‘zfs destroy’ instead of ‘zpool destroy’. DOH!

zfs destroy zfsdiskpool@Sat

Script to Run Handbrake Recursively Through a Folder Tree

| Comments

Handbrake is a fantastic tool for (among other uses), converting videos into mobile formats. It is extremely easy to use and can usually get a video properly converted in just a few clicks. To get Videos encoded for use on my phone, I use the “iPhone & iPod Touch” preset. It will convert your video to .mp4 as well as scale it down to a consumable size. This format will work on any smartphone I’ve seen.

My issue is that when converting a folder full of videos, I don’t want to have to use the gui to add a bunch of videos to the queue one by one. Its a very clicky process. This simple bash script will walk handbrake through all the files in a selected folder (and its subfolders). This uses the find command to traverse recursively through a directory structure. It will place the transcoded file in the same folder as its source and change its extension to “.mp4”.

Usage: handbrakefolder.sh [FOLDER] Run handbrake on all the files contained in [FOLDER]. (the current directory by default)

handbrakefolder.sh
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
#
# Change this to specify a different handbrake preset. You can list them by running: "HandBrakeCLI --preset-list"
#
PRESET="iPhone & iPod Touch"
if [ -z "$1" ] ; then
    TRANSCODEDIR="."
else
    TRANSCODEDIR="$1"
fi
    find "$TRANSCODEDIR"/* -type f -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%\.*}".mp4 --preset="$PRESET"' __ {} \;

Save that into a .sh file like “handbrakefolder.sh” and grant it the execute permission (chmod +x handbrakefolder.sh).

Thanks to Vinnie and http://mywiki.wooledge.org/UsingFind for their help in this.

Now you can simply execute this script against a folder containing your video files. like this:

For a folder structure like this:
Videos
-> show1
    vid1.avi
-> show2
    -> season 1
        ep1.avi
        ep2.avi
    -> season 2
        ep1.avi
        ep2.avi
-> show3
    vid1.avi
    vid2.avi

hostname% handbrakefolder.sh Videos
...
....
...
When done, it will look like this:
Videos
-> show1
    vid1.avi
    vid1.mp4
-> show2
    -> season 1
        ep1.avi
        ep1.mp4
        ep2.avi
        ep2.mp4
    -> season 2
        ep1.avi
        ep1.mp4
        ep2.avi
        ep2.mp4
-> show3
    vid1.avi
    vid1.mp4
    vid2.avi
    vid2.mp4

Write Zero’s to Disk Infinite Loop

| Comments

I was bored… So this is a little bash script i wrote that will write zero’s to a hard disk infinately until you press CTRL+C. It uses dcfldd instead of plain dd because i like the progress output it provides.

#!/bin/bash
echo -e "Which disk would you like to wipe out? (sda, sdb, sdc)?   \c"
read DISK
read -p "You picked "$DISK", are you sure? (y/n)" -n 1
if [[ $REPLY =~ ^[Yy]$ ]]
then
C=1
for (( ; ; ))
do
        echo -e "\nStarting zero Sweep number "$C" ..."
        dcfldd if=/dev/zero of=/dev/$DISK
        echo "Zero's written to Disk "$C" time(s)"
        echo "[ hit CTRL+C to stop ]"
        let C=C+1
done
fi