Redirection of command output — a scrollable alternative to |more

July 30, 2009 by jimbobmcgee

I’m sure many Linux people already know this, but I discovered it today and figured I’d keep it on hand for when I need it again (that’s what this blog is for, after all).  I knew it was possible to redirect output to a file using >, redirect input from a file using < and chain the output of one command as the input of another using | but I didn’t know it was possible to redirect the output of a command (or series of commands) using <(...) too.

I’m used to doing things like ls -lrt | more to page the results of a directory listing, for example, but as a Windows user, I’m too used to being able to scroll my terminal (or command prompt) output to go back and forward and you just can’t do that in a pure terminal like I have been dealing with recently.

Enter the <(...) construct:

vi <(ls -lrt)

Now the output of ls -lrt is redirected to the vi editor as some kind of pseudo-file.  I can page up and down to my heart’s content.

I also discovered the du and comm utilities today (told you I was new) and using a combination of all of them can now compare the size of folders under two separate parents:

vi <(comm <(cd /dir1; du .) <(cd /dir2; du .))

This changes the current directory to /dir1, spools the size of all subfolders to a pseudo-file, changes the current directory to /dir2, spools the size of all subfolders to another pseudo-file, spools the comparison of the two pseudo-files to a third pseudo-file and shows that file in vi, for me to look around.

Perfect for eyeballing the results of a local rsync.  It took a whole batch file to do the same last time I tried in Windows.

Database Project Deployment — An introduction to the DependencyList

September 26, 2008 by jimbobmcgee

Recently, I have been working with Database Projects within Visual Studio 2005 (yes, I’m set in my ways — I haven’t got around to VS2008 yet!!).  I like the ability to source control my creation scripts and stored procedures and I’m happy to use the VS IDE to write my SQL code and running individual scripts against multiple development Database References is a breeze.

However, deploying the finished scripts to a production database is a bit of a nightmare.  Essentially, if each script file represents a single database object, you have to ensure that you run them all in the correct order — especially if you have foreign key constraints (you do have foreign key constraints, don’t you?!).  Ordering all these scripts manually is a royal pain.

After the second or third time of being stuck in this situation, I decided enough is enough and set about writing a small app to do the job for me.  The results of this formed the mighty DependencyList.

Read the rest of this entry »

Oracle service crashes on OracleConnection.Open()

March 4, 2008 by jimbobmcgee

We recently had a situation here where the opening of a .NET connection to an Oracle 10g database caused the entire database to crash. This was indicated by the Event Log entry:

The OracleService<SID> service terminated unexpectedly.
It has done this <n> time(s).

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

This was using some library code that we had developed and used successfully on numerous occasions, so it had us truly stumped.

After much soul-searching, one of my colleagues eventually narrowed it down to the length of the .NET project name. The project, when compiled, created a EXE file that had a really long name, which caused Oracle to shit bricks.

Wonderful. I hate how Oracle has such a problem with large object names.

Also, I’d love to know how an Oracle DBA would approach such a failure. How would it even be recorded? There are so many different log files in a standard Oracle installation that I really wonder where you might begin?

Service configuration error – Event ID 5000 (ioibmurhynrxkw0zxkyrvfn0boyyufow)

September 26, 2007 by jimbobmcgee

I was recently bugged by an error in a Windows Service I was developing that, when deployed an started, immediately stopped. My log files showed nothing, which suggested that the exception was happening before my logging and exception handlers started.

Examining the Application Event Log, I found the following error:

Event Type: ErrorEvent
Source: .NET Runtime 2.0 Error Reporting
Event Category: None
Event ID: 5000
Date: 26/09/2007
Time: 20:17:53
User: N/A
Computer: theDeploymentServer
Description:
EventType clr20r3, P1 theService.exe, P2 1.0.0.0, P3 46fa9f5d, P4 system.configuration, P5 2.0.0.0, P6 4333ae78, P7 1a2, P8 136, P9 ioibmurhynrxkw0zxkyrvfn0boyyufow, P10 NIL.
For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

Not the most helpful of errors, but I could see the system.configuration entry, so I started with the theService.exe.config file, emptying the file of any meaningful data and adding it back in piece by piece until I recreated the error.

The error occurred on the following appSetting entry:

<add key="PluginsFolder" value="C:\Program Files (x86)\A&B\theService\" />

I realised that the appSetting contained an ampersand (&) witin its value, I realised that ampersand is a reserved character in XML and so the .NET configuration parser couldn’t validate the .config file.

To resolve this I replaced the ampersand with its XML-compliant counterpart (&amp;), so the key now read:

<add key="PluginsFolder" value="C:\Program Files (x86)\A&amp;B Company\theService\" />

Granted this looks a little weird but it solved the problem!

Excessive recompilations when using VirtualPathProvider

September 20, 2007 by jimbobmcgee

This is a quick pointer for anyone implementing a VirtualPathProvider in their ASP.NET applications. I’ve read a number of tutorials on VPPs but none really touched on this issue.

If you do not implement a method for VirtualPathProvider.GetFileHash(...), calls to this method will return null/Nothing.

If this happens, ASP.NET’s build/compile system doesn’t remember that it has already compiled the file and attempts to do so again. After 15 compiles, the AppDomain is unloaded and the application restarts. This can cause major irritation, particularly with performance, as the recompiles take time.

To get around it in my app, I am overriding GetFileHash to return a string concatenation of the VirtualFile’s name and Last Modified Date. If anyone knows of a better hash, then please let me know.

Reinstating the GUI login page

September 20, 2007 by jimbobmcgee

Having just completed a 5-hour install process I, spent another two hours trying to fix up an issue I had with the login screen.

Having messed about with the options on the Login Screen, I inadvertently configured the X Server to try to login to a XDMCP server, by setting the startup server to Chooser.

When I rebooted, I couldn’t find any XDMCP servers, so I couldn’t login. I thought I’d try booting to a terminal mode, only to find that the kboot loader loaded Fedora if I left the keyboard idle for too long (about three seconds0).

Eventually I found out that I could get to a terminal from the XDMCP screen by pressing CTRL+ALT+F1. After that, I could log in as root and edit the GDM config file with VIM:
vi /etc/gdm/custom.conf
allowed me to edit the file, so I scrolled down to the [servers] section and changed the entry from:

[servers]
0=Chooser

to:

[servers]
0=Standard

After rebooting, the regular login screen was displayed.

I’ve learned two things from this:

  1. CTRL+ALT+F1 opens a terminal from the login screen
  2. I’m not going to mess with the startup screen again (I don’t even know what an XDMCP server is, let alone why I might want one!)