Friday, November 6, 2009

Is Hyper Threading enabled?

Needed a quick way to check if Hyper Threading was enabled on some RHEL boxes, ended up writing a quick "script" that can be copied onto the command line.

I'll go through it line by line just for fun:

First we grab all lines matching "core id" from /proc/cpuinfo, sort them (in case the id's where not listed in numeric order), list the unique values and count them
cores=`grep "core id" /proc/cpuinfo|sort|uniq|wc -l`
Using grep I count the number of lines matching "processor" from /proc/cpuinfo
procs=`grep -c "processor" /proc/cpuinfo`
If we fine less cores the processors then Hyper Threading must be on
if [[ "$cores" -lt "$procs" ]]; then
echo -e "\n$HOSTNAME: cores=$cores, processors=$procs\n HyperThreading: Enabled"

If we find the same number of processors and cores the Hyper Threading is off
elif [[ "$cores" -eq "$procs" ]]; then
echo -e "\n$HOSTNAME: cores=$cores, processors=$procs\n HyperThreading: Disabled"

If neither case matches then we have run into a failure, or our math doesn't work on this particular box
else
echo "epic failure"
fi

And the whole thing...
cores=`grep "core id" /proc/cpuinfo|sort|uniq|wc -l`
procs=`grep -c "processor" /proc/cpuinfo`
if [[ "$cores" -lt "$procs" ]]; then
echo -e "\n$HOSTNAME: cores=$cores, processors=$procs\n HyperThreading: Enabled"
elif [[ "$cores" -eq "$procs" ]]; then
echo -e "\n$HOSTNAME: cores=$cores, processors=$procs\n HyperThreading: Disabled"
else
echo "epic failure"
fi

Wednesday, November 4, 2009

How I learned to Stop Worrying and Love the Bomb istat

I was recently tasked with organizing 137k+ small .jpg files into a folder structure based on year and quarter, why? users opening this directory with a ftp client complained that it took a "long time" to get a directory listing... apparently 15 - 20 minutes each time they opened the directory, honestly if a program didn't return anything in 15 minutes I would probably kill it and blame the server!

I really didn't think too much of the problem, in my head I though "i'll just use 'find' and 'stat'", which would have worked perfectly EXCEPT that I had to do this on a AIX 4.3 server and mounting the filesystem remotely was not an option.

A few problems with AIX 4.3 - no 'stat' command, in AIX 5.x you can install the coreutils rpm from the AIX toolbox to overcome this problem but you are up the creek without a paddle in 4.3! Also 'find' doesn't have all of the options you would usually have available on a newer version of linux - this was an issue in my case since I had to put the files into subdirectories (example: /basedirectory/2008/Q3) which meant that when searching for files to process in the basedirectory I did not want to descend into the yearly and quarterly subdirectories, easy with the -maxdepth option - which is not available in 4.3.

I ended up getting around the lack of -maxdepth in the find command by using the -prune option to remove subdirectories from processing, because the basedirectoy did not contain any directories except 200{8,9}/Q{1..4} this task was simplified even further by providing a common directory 'Q*'.

The lack of the 'stat' command had me banging my head against 'ls' for a day or so... The problem I have with 'ls' is in trying to get the year from 'ls -l', it works great for files older then 180 days but files less then 180 days are listed with the file modification timestamp in place of the year. I toyed with awk'ing the year/modifaction time column and checking if the value was an integer, which does work but you run into issues if your script is running within 180 days of the end of the year and examining files from the previous year, all the files will have timestamps which would cause you to examine the value of the current month vs. the month of the file being examined to determine the correct year - logic that I was uninterested in writing out.

Enter in my new most loved command in AIX: 'istat'
I was lucky enough to find a post mentioning 'istat' which "displays the i-node information for a particular file". 'istat' is simliar to the linux 'stat' command although it does not allow you modify the output using command line switches - nothing a little grep and awk won't fix! What 'istat' does do is handily format data about file creation, modification and access in an unambiguous matter - dates are always shown in the same format, unlike 'ls -l'. Without this tool I was writing a longer and longer script to deal with corner cases dealing with files modified 180 days ago and files modified around the last 3 months of the year - with 'istat' I was able to make my script much simpler and rely on the computer to hand me information in an consistent format.

I would be surprised if anyone has to solve this same problem but I will post the script anyways, as a warning this script is slow - 'istat' is not a tool for performance! Also working 'xargs' into the mix would make a more elegant solution in-place of 'find' and 'cat'.

In the following script I have disabled the actual move command - this will only print what would happen! uncomment the line beginning with 'mv' and it will move files.


#!/usr/bin/ksh
#
# organize files ending in $fileextension in $basedir
# by moving them into subdirectories $basedir/$year/$quarter
#


# backdate variable controls how many days old a file must be before
# it is considered for processing, 92 days is approx 3 months
# if you don't believe me ask google "3 months in days"
backdate=92

fileext=YOUR_FILE_EXTENTION
outfile=/tmp/jpg_organizer.out
basedir=YOUR_BASE_DIRECTORY

errors=0

# function to calulate which quarter a month lives in
calculate_quarter() {
case $month in
Jan|Feb|Mar)
quarter="Q1"
;;
Apr|May|Jun)
quarter="Q2"
;;
Jul|Aug|Sep)
quarter="Q3"
;;
Oct|Nov|Dec)
quarter="Q4"
;;
esac
}

# rudimentary error checking
error_check() {
let errors="$errors + $?"
if [[ $errors -gt 0 ]]; then
echo "encountered an error, exiting"
exit $?
fi
}

# find files older then $backdate and move them into $basedir/$year/$quarter directories
find $basedir -name Q\* -prune -o -name \*$fileext -mtime +$backdate -type f -print > $outfile
error_check
for i in `cat $outfile` ; do
filename=$i
fileattrib=`istat $i | grep "Last modified:"`
month=`echo $fileattrib | awk '{print $4}'`
year=`echo $fileattrib | awk '{print $7}'`
calculate_quarter
if [[ ! -d $basedir/$year/$quarter ]]; then
mkdir -p $basedir/$year/$quarter
error_check
fi
echo "moving:$filename to $basedir/$year/$quarter/"
#mv $filename $basedir/$year/$quarter/
error_check
done

rm $outfile

exit 0

Monday, October 26, 2009

AIX syslogd and splunk (and more)

AIX is what I would call a 'batteries not-included' OS; the vanilla DVD install leaves you with a functioning system that has telnet (with root access) enabled, no OpenSSL/OpenSSH, korn shell without autocomplete (must be enables 'set -o vi'), no logging, etc...
Since I work around a lot of RedHat boxes I tend to modify the AIX servers to have a simlar setup to RHEL, here are some of the steps I take:

Install the following rpm's from the aix toolbox:
bash (add /usr/bin/bash to /etc/security/login.cfg)
curl
coreutils
less
lsof
python
rsync
sudo
unzip
wget

Install OpenSSL and OpenSSH

Change root home directory to /root and change shell to bash:
mkdir /root && chuser home=/root shell=/usr/bin/bash root
Modify prompt for all users:
# Set bash prompt to be much more linux like
if [[ "$TERM" == "xterm" ]];then
if [[ "$SHELL" == "/usr/bin/bash" || "$SHELL" == "/bin/bash" ]];then
if [[ "$UID" -eq 0 ]];then
PS1="\[\033]0;\u@\h:\w\007\][\[\033[31;1m\]\u\[\033[0m\]@\h \W]# "
else
PS1="\[\033]0;\u@\h:\w\007\][\u@\h \W]\$ "
fi
fi
fi
Change logging setup:
# Linux-ify the AIX logging setup and enable automagic rotation
# Everything but mail and auth to messages
*.info;mail.none;auth.none /var/log/messages rotate size 10m files 10 compress
# Auth to secure
auth.debug /var/log/secure rotate size 10m files 10 compress
# Mail to maillog
mail.debug /var/log/maillog rotate size 10m files 10 compress
# Emergency messages to all users
*.emerg *
*.info;mail.none @NETWORK_LOG_SERVER
Remove "Message forwarded from hostname:" from remote logging output:
chssys -s syslogd -a "-n" ; stopsrc -s syslogd ; startsrc -s syslogd
Run aixpert to enable a much higher level of security:
aixpert -l high

Wednesday, March 4, 2009

Lotus Notes 8.5 on Fedora 10 x86_64

32-bit packages required for notes 8.5 to work on Fedora 10 x86_64. Notes will install fine without these but will not run.

libxkbfile-1.0.4-5.fc9.i386
libgnomecanvas-2.20.1.1-4.fc10.i386
libgnomeprint22-2.18.5-1.fc10.i386
libgnomeprintui22-2.18.3-1.fc10.i386
gnome-vfs2-2.24.0-3.fc10.i386
libgnome-2.24.1-9.fc10.i386
libgnomeui-2.24.0-2.fc10.i386
libXScrnSaver-1.1.3-1.fc10.i386
libcanberra-gtk2-0.10-3.fc10.i386
gtk-nodoka-engine-0.7.2-1.fc10.i386

Of course installing these also carries a lot of dependency baggage.

And a handy one liner:
sudo yum -y install libxkbfile-1.0.4-5.fc9.i386 libgnomecanvas-2.20.1.1-4.fc10.i386 libgnomeprint22-2.18.5-1.fc10.i386 libgnomeprintui22-2.18.3-1.fc10.i386 gnome-vfs2-2.24.0-3.fc10.i386 libgnome-2.24.1-9.fc10.i386 libgnomeui-2.24.0-2.fc10.i386 libXScrnSaver-1.1.3-1.fc10.i386 libcanberra-gtk2-0.10-3.fc10.i386

Wednesday, January 28, 2009

ardour vsti support

To enable vsti support in ardour you must compile it from source, this has to do with licensing of the steinberg vst sdk. Here are my basic instructions for doing this on Fedora 10, note that I have already installed the ccrma repository and kernel as well as many packages referenced in my earlier post.

cd ~/Download/ && wget http://releases.ardour.org/ardour-2.7.1.tar.bz2

bunzip2 ardour-2.7.1.tar.bz2 && tar xf ardour-2.7.1.tar && cd ardour-2.7.1

get vst2.3 zip from steinberg, put in ~/Download/ardour-2.7.1/libs/fst

yum install liblrdf-devel libgnomecanvas-devel aubio-devel fftw-devel libsxlt-devel gcc-c++ boost-devel

cd ~/Download/ardour-2.7.1/
scons VST=1
scons install

Friday, September 12, 2008

Installing IBM Tape System Reporter

On Sept. 8th I got an email from IBM notifying me that Tape System Reporter had been released, it is supposed to:
The IBM Tape System Reporter (TSR) application enables operators and administrators of the TS3500 Tape Library to monitor and report on storage devices in an enterprise environment
I have two TS3500 with 12 drives between them so this sounded pretty good, I thought I would install it and see what it can offer. I am a big fan of reporting since usually I can gain some ground with management to buy more stuff if I have pretty graphs in my hands!

Unfortunately I was in for a ride on this, I should have known when I read this:
It is not the intent of this documentation to explain how to download and use
Derby to establish a database that contains the authorizations for using the IBM
Tape System Reporter application.
Which means that I had to learn how to install a new application (apache Derby) with little help from IBM... I was able to accomplish this - though at the end I had not read the requirements well enough and found that I did NOT have ALMS licensed so even though I had the app installed correctly I couldn't get the data out of it... Either way here are the steps I went through to install this app.

You need Windows XP or 2000 for the install so I booted up a XP virtual machine using Virtual Box.

  1. Download and install the latest version of java from http://www.java.com, derby is a java database...
  2. Install Adobe Reader from http://www.adobe.com/products/acrobat/readstep2.html, the install docs are in PDF and copy/paste from my main OS to the virtual box doesnt always work...
  3. Download the latest version of derby from http://db.apache.org/derby/derby_downloads.html
  4. Extract derby, I chose to go with c:\derby_10\ like the doc shows, earlier I had tried putting it in c:\program files\derby\ but didn't have much luck - I started to wonder if the %PATH% variables where getting stuck on the spaces in the directory structure.
  5. Time to set some variables, you can set these on the command line for one time use or set them in the global profile, I chose the later:
    1. Right click on "My Computer", click on properties
    2. select the 'Advanced' tab, click on Environment variables
    3. on the lower half of the window that opens (System Variables) click 'New'
    4. Variable name = DERBY_HOME, Variable value = C:\Derby_10 (or the directory you expanded the derby zip into). Click OK
    5. Click on 'Path' in the System Variables section, choose 'Edit'
    6. To the end of the Variable value add the following: ;%DERBY_HOME%\bin
  6. Good time to validate those variables, open a command prompt (Start->Run->cmd) and type the following:
    1. echo %DERBY_HOME%
      • output should be the variable value you set in step 5, in my case c:\derby_10
    2. ij
      • this command is part of the derby package, output should look something like:
        version 10.4

        ij>
      • if that is working simply type 'quit;' to exit the ij shell, if you dont see the ij prompt your system variables are not set correctly!
  7. At this point the directions from IBM start to lose their usefulness, some of the files they mention don't exist, other required files are not mentioned... good thing they had that disclaimer at the beginning of the document!
  8. Navigate to %DERBY_HOME\bin and copy the derby_common, startNetworkServer and stopNetworkServer scripts to the main derby folder (one folder down). The instructions mention a derby.properties file, i believe this would only exist if you had previously used derby so if it doesn't exist you can create it in the next step
  9. create a new file and save it as derby.properties in %DERBY_HOME%, remember that if you create the file with notepad (as I did) that you must set the "Save as type:" to "All Files" or windows will magically append .txt to the filename.
  10. Add the following to your %DERBY_HOME%/derby.properties file, in this example I am using tsruser as the username and tsrpass as the password - adjust accordingly.
    derby.connection.require Authentication=true

    derby.authentication.provider=BUILTIN

    derby.user.tsruser=tsrpass

    derby.databasedefaultConnectionMode=fullAccess
  11. Now you need to edit the startNetworkServer script in %DERBY_HOME%, if you have your CLASSPATH setup for derby you can follow the IBM instructions, I did not so I had a much longer string to enter. Note that in my example I am setting the directory for the database to be created in as %DERBY_HOM%\tsrdb. Add the following to the end of the script (should be one long line):
    java -classpath %DERBY_HOME%\lib\derby.jar;%DERBY_HOME%\lib\derbynet.jar;%DERBY_HOME%\lib\derbyclient.jar;%DERBY_HOME%\lib\derbytools.jar;%DERBY_HOME%\lib\derbyrun.jar -Dderby.system.home=%DERBY_HOME%\tsrdb\ org.apache.derby.drda.NetworkServerControl start -h localhost -p 1527
  12. Add a vary similar line to %DERBY_HOME%\stopNetworkServer:
    java -classpath %DERBY_HOME%\lib\derby.jar;%DERBY_HOME%\lib\derbynet.jar;%DERBY_HOME%\lib\derbyclient.jar;%DERBY_HOME%\lib\derbytools.jar;%DERBY_HOME%\lib\derbyrun.jar -Dderby.system.home=%DERBY_HOME%\tsrdb\ org.apache.derby.drda.NetworkServerControl shutdown -h localhost -p 1527
  13. You can test the start and stop scripts at this point by double clicking on them, the start script should open a command window that accepts no input and the stop script should open a command window and then close both the start and stop windows. If everything is working correctly go to the next step, otherwise double check everything.
  14. Time to create the database - start the derby server by double clicking on %DERBY_HOME%\startNetworkServer, open a command window and get an ij prompt by typing 'ij'. Enter the following text to create the database - I am using tsrdb as the database name, tsruser as the username and tsrpass as the password
    connect 'jdbc:derby://localhost:1527/tsrdb;create=true;user=tsruser;pass=tsrpass';
  15. Check the %DERBY_HOME% directory, you should see a folder matching your database name (tsrdb in my examples). If you do then you should have the derby portion of the install complete!
  16. Install the DB2 Run-Time Client Lite that is mentioned as a prereq in the docs, you can find it at http://www-01.ibm.com/support/docview.wss?uid=ssg1S4000680. I took the defaults and did a 'Typical' install which worked fine.
  17. Download the TSR zip file, it can be found on the page mentioned in step 16. Extract it to a directory of your choosing, I like c:\Program Files\tsr
  18. Now we can check on the database connectivity and create the table to store data in:
    • Double click on the tsr executable, from the menu choose 'Database->Setup'.
    • Enter your database name (tsrdb) the IP (localhost) and port (1527)
    • Click Test, enter the username (tsruser) and password (tsrpass) and click OK
    • The system will churn for a minute and should say 'Test Passed'.
    • Select the 'Table' tab while still in the Setup window and choose a table name, according to IBM this table will be used for storing the library performance data, I chose 'tsrdata'.
    • Click create, you will need to enter your username and password again (tsruser/tsrpass) and click OK
    • Output should be 'Table created successfully', click OK and then click OK again.
  19. Time to connect to the database and begin collecting data
    • Click 'Database->Connect'
    • enter username and password, click OK, should get 'Connection successful'
    • Click 'File->Start Monitoring'
    • enter the IP address or dns entry of the TS3500 you would like to monitor and click OK
    • A window should open and have some output in it like 'Starting Monitor on Tape Library yourlibnamehere'
    • cant say much more, without ALMS licensed this is as far as I got :( but hopefully it works!
Hopefully this helps someone, if I get an ALMS license soon I would like to post some screenshots of the app actually displaying useful data. Maybe someone can send me some!

Monday, July 21, 2008

Fedora Multimedia Workstation

My default Fedora 10 install packages plus ccrma repos and meta package/kernel for low latency audio workstation with windows vsti's. With this setup I can run an alesis trigger io and trigger samples in XLN Audio Addictive Drums without having to run windows, plus I get SUPER low latency with low cost sound cards (even onboard is below 3ms), currently running a turtle beach riviera on an old Pentium 4 and getting 1.6ms

# setup yum repos
sudo rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm \
http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm \
http://rpm.livna.org/livna-release-9.rpm \
http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm

# install apps
sudo yum -y install bash-completion nautilus-open-terminal gstreamer-plugins-bad gstreamer-plugins-ugly gstreamer-ffmpeg k3b-extras-freeworld lame easytag mplayer gnome-mplayer gecko-mediaplayer mencoder libdvdcss flash-plugin AdobeReader_enu clusterssh compat-libstdc++-33 gcc wine wine-devel grip unrar vnc

# 64-bit flash support
yum install flash-plugin nspluginwrapper.x86_64 nspluginwrapper.i386 alsa-plugins-pulseaudio.i386 libcurl.i386

# nvidia driver
sudo yum -y install akmod-nvidia

# ati driver
sudo yum -y install akmod-fglrx

# ccrma repos add extra audio workstation tools and includes the low latency kernel
sudo rpm -Uvh http://ccrma.stanford.edu/planetccrma/mirror/fedora/linux/planetccrma/10/i386/planetccrma-repo-1.1-2.fc10.ccrma.noarch.rpm

# meta package for all major ccrma apps, this is a LARGE compilation and will take a while to download on a slow connection! (in my case 259mb with dependencies)
sudo yum -y install planetccrma-apps

# low latency kernel, first step is to allow Fedora to keep more kernels which can be done by changing the 'installonly_limit=3' line to 'installonly_limit=0', then running the following command
sudo yum -y install planetccrma-core

# get rid of "Could not load Mozilla. HTML rendering will be disabled." when running wine
wine iexplore http://www.winehq.com