As I write this, spring is in the air. The days are getting longer. The birds and the bees are busy building nests. The signs of renewing life are everywhere. In this hormone- and pheromone-laden environment, a techie's attention naturally turns to...connecting to the iSeries database from his or her Linux box.
No man is an island, as the saying goes, and nowhere is this truism more applicable than to operating systems. Those operating systems that were designed to be islands are no longer with us. Those whose designers took a more enlightened view of the world are now thriving. So it is with our beloved iSeries. IBM has been continually opening up OS/400 since V3R7 (or thereabouts). And the current version, V5R1 offers up storage and data to other operating systems in quite a few ways.
In this article, I'll give an overview of the more prevalent and convenient means of accessing iSeries data from my favorite non-iSeries operating system: Linux. Future articles will cover the nuts and bolts of configuring and using these access options.
Emulation, Storage, or Data?
When someone asks me about the connectivity options between OS/400 and Linux, I usually have to prompt him to specify which connectivity, since I distinguish three separate categories. First, there is 5250 emulation, which I'll only make mention of now, since I've discussed that in my last two columns. Second, there is storage access. This category refers to the use of an iSeries machine as a network storage server (NSS). In this scenario, the iSeries provides space in its pricey hard drive real estate for network clients (such as Linux and Windows PCs) to store files. Finally, there is the access of the iSeries database from programs running on other machines. Let's review the latter two options.
The iSeries as a Network Storage Server
There are benefits to using the iSeries as an NSS. It certainly eases the backup/restore management burden of critical PC files if they reside on the iSeries, since they can be backed up along with any of the regular files stored within the Integrated File System (IFS). Furthermore, the iSeries' well-deserved reputation for availability and bullet-proof hardware (recent hard drive failures excepted) provides a compelling combination for the PC administrator looking for a reliable server.
There are a few disadvantages that you must take into account before committing the iSeries to NSS duty, however. By IBM's own admission, the iSeries NetServer is not designed to be a file server for a huge Windows network. In this case, size does matter! For my small office (about 30 users), NetServer functions well and I'm pleased. I've seen varying reports in the Usenet groups--to paraphrase, "He said that she said that IBM said to keep your user count less than 50 or so." In short, your mileage will vary by the number of processors, disk arms, and other iSeries minutiae that affect performance.
A bigger impediment to your plans might be the cost of iSeries disk space. If you have users who are prone to saving the recipes, jokes, and images they receive from the internet into their shared drive space, then you have the computer equivalent of building a "U-Store-It" locker in the middle of downtown Manhattan. Clearly, it would not be a good investment. A well-defined acceptable-use policy can help you in this department.
FTP
When I decided that using the iSeries as an NSS made sense for me, I was pleased to find that it could do so for my Linux clients as easily as it does for my Windows clients. To start off with, OS/400 provides an FTP server that can be used from any client equipped with FTP client software (which includes virtually all common operating systems in use today).
Setting up the server on the iSeries is done via the iSeries Operations Navigator. Select Network->Servers->TCP/IP, and then right-click the icon for the FTP server properties. Once you have dismissed the set-up dialog, start the server by once again right-clicking on the FTP Server icon; then click on "Start." Once the iSeries has fired up the requisite programs, you connect to it by first issuing the command ftp youras400, then entering the required user ID and password. Once you've successfully logged on, you'll be greeted with the prompt "ftp>." If you're new to FTP, issuing the command help will provide you with a list of available commands. I won't write a treatise on FTP, since you can read the man page on your Linux machine for further information (man ftp). You also will want to read about FTP on the iSeries in the IBM documentation to learn about the slight differences in navigating FTP on an iSeries versus a Unix/Linux or Windows box.
RSYNC
Another option for transferring data files between the iSeries and Linux is available to those who have spent the hundred bucks (or so) to buy and install V4R5 5769-SS1 Option 33 OS/400 Private Address Space Environment, also known as PASE. PASE gives you the ability to run binaries that were compiled for AIX (IBM's version of Unix). The particular package that I find useful is an open-source project called rsync. This utility is designed to allow you to synchronize files between two or more computers (or two different directories on the same computer). I've found it useful for doing various tasks, such as backing up my laptop computer to my desktop system. I've even used it for keeping two servers mirrored, making one a hot spare for the other. If you venture to rsync's site, you'll find a pre-compiled version that you can download to your PC. I'll delve into the finer points of installing rsync and other AIX binaries in a future column. (For those wanting to work ahead, please note that you need to run rsync with the "-daemon" switch on the iSeries.)
NFS
Although Windows made peer-to-peer networking popular, it certainly doesn't have a monopoly on file sharing. IBM has seen fit to add to the OS/400 TCP/IP suite the Network File System, also known as NFS. The NFS server permits you to mount an iSeries directory (known as an "export" in the Unix/Linux world and a "network share" in the Microsoft world) onto a mount point on the Linux machine. The result is that the iSeries directory appears to be a directory local to your Linux machine, much like a Windows network shared folder appears as a drive letter on your Windows box. To mount an iSeries export from Linux, you need to configure and start the NFS server on the iSeries. As with FTP, you can accomplish this via the iSeries Operations Navigator; but you also can configure NFS using more traditional green-screen applications. For further information, I suggest that you read the Redbook Exploring NFS on AS/400 (SG24-2158-00), which you can find at IBM's Redbook Web site. Pay particular attention to "Chapter 4: NFS Security," since you'll need to learn about user IDs (UIDs) and group IDs (GIDs).
Those working ahead will want to note that making the UID on your iSeries user profile (via CRTUSRPRF or CHGUSRPRF) match that of your user profile on your Linux machine will make your NFS experience more pleasant. You can find your Linux UID by issuing the command grep "YourLinuxUserName" /etc/passwd . The UID will be found in the third field of the line. (Fields are separated with the colon character).
Although I have been writing this as though you would always want to transfer files to/from your Linux machine to the iSeries from the Linux side, you can perform the transfers from the iSeries side of the equation. I use this scenario to have my nightly iSeries backup program mount shares on my various Linux servers. Once done, the program then copies various files from the Linux machines to its own IFS so that they can be saved to tape. Unfortunately, IBM won't allow you to back up files across the network via the SAV command (perhaps so as not to eat into its BMRS software?), so I must resort to the copy first. It's not elegant, but it does work. As with the iSeries, you must configure an FTP or NFS server on your Linux box prior to accessing it from the iSeries.
SMB
The final access method available for the Linux user is Server Message Block (SMB), the lingua franca of Microsoft networking. I saved this for last not because it's the best but because it's not available to everyone. As I mentioned in last month's article, writing software to a Microsoft API is like hitting a moving target. And in the case of the NetServer on OS/400 V4R5, IBM's shot was a little behind the target. The SMB protocol they implemented on this release was not the newer one implemented by the Samba team. Samba is the open-source project that implements SMB networking on Unix/Linux machines. The first time I attempted to mount a NetServer share on my Linux machine, I was completely stumped by the fact that the mount command successfully completed, but there were no files showing under the mounted directory. Arrgh! I tried everything (short of slaughtering a sheep and placing its entrails on the keyboard) but to no avail. From what I've read, IBM has corrected that problem on V5R1, but since every machine for which I have responsibility is at V4R5 or earlier, I have not been able to confirm that. (Perhaps one of the readers will drop me a note and let me know?) If the problem has indeed been fixed, then you'll be able to omit the NFS server on the iSeries and do everything through Netserver, which will be much more convenient from a management perspective. And you'll be able to avoid the UID/GID situation too.
The iSeries as a Data Server
Having looked at the iSeries as a network storage server, we now turn our attention to the iSeries as a database server. You might think that connecting a Linux-hosted program to the iSeries would require some serious voodoo. But thanks to IBM's warm embrace of standards, the task is rather straightforward and simple. Let's look at some of your options.
The One-Shot Query
Imagine that you have a database file (table) on your iSeries that contains information you would like to work with in a spreadsheet format--perhaps the StarOffice spreadsheet. The simplest method in this scenario is to extract the appropriate records (rows) using the iSeries query tool of choice (Query/400, Query Manager, etc.) and then save the results into another database file. From there, it's simple to use the CPYTOIMPF command to convert the newly-created file into a tab- or command-delimited file on the IFS (my preference being tab-delimited with no string identifier because it's easier to use); then, use FTP from your Linux machine to transfer that file to your PC.
To test this scenario, I created a subset of approximately 8,500 rows from one of my database tables. This tab-delimited file was then FTPed to my Linux laptop, and from four different Linux spreadsheet programs (KSpread, Gnumeric, StarOffice 5.2, and StarOffice 6.0), I was able to import the tab-delimited file with no trouble. In fact, if you give your downloaded file the extension "csv," StarOffice will recognize the file type and open the file directly, without your having to go through an import step.
In lieu of FTP, you can transfer the file via an NFS-mounted directory or with V5R1 via an SMB share. You need to take care, however, to ensure that you allow for the code page differences between Linux and OS/400. A transfer through FTP gets it right without any additional gyrations.
JDBC
If you've been doing any programming in Java, then you've seen this acronym before. For truly cross-platform database connectivity, nothing beats Java. The jt400.jar file that you use on your iSeries is the same file that you need on your Linux machine to connect your Java programs or servlets to the iSeries database. So, if you are doing any Java work on your Linux box, the decision is simple: Use JDBC.
But what if you aren't writing Java programs? What user-level programs are available? The most obvious example I can offer is StarOffice, in either the free Version 5.2 or the for-purchase Version 6.0 (about $80). StarOffice can use JDBC data sources in the same fashion that Microsoft's Office Suite uses ODBC data sources (which should come as no surprise, since the same company [Sun Systems] owns both StarOffice and Java). StarOffice is not the only example. There are any number of Java-based utilities available on SourceForge. A quick search of the site with the term "Java" returned pages of results. Given that many of them are report writers, it's a cinch that at least some can take advantage of a JDBC connection to the iSeries.
ODBC
This de facto data access standard is not foreign to Linux. The open-source unixODBC project provides an ODBC driver and data source management facility similar to the one provided in Microsoft Windows. In fact, if you are at all comfortable using the ODBC manager on Windows, then you'll have no problem with the ODBC Data Source Administrator on Linux. Many of the newer distributions, such as Red Hat Linux 7.3, include unixODBC as part of their default installation. If yours does not, simply visit the unixODBC Web site to obtain the software and installation instructions for your distribution.
Once you have unixODBC loaded on your computer, your next visit should be to IBM to pick up the ODBC driver and instructions for the iSeries database. After the driver has been downloaded, installed, and configured, you'll have the same functionality from your Linux machine as you do from your Windows machine. Whereas the JDBC drivers had a somewhat limited range of languages and programs that would be able to use ODBC, the driver has many more applications. Besides the aforementioned StarOffice, which can use ODBC data sources, we have many more computer languages. For example, if you are doing your Web application programming in PERL or PHP, you'll be able to access the iSeries database with ease via the ODBC driver.
Surprised?
I know that many people are put off from using Linux because they have become comfortable with what they currently use. Changing a familiar environment is always stressful, but as you've seen from this article, there's nothing mystical or even much different about using Linux for iSeries access (except that you won't need to reboot constantly).
In my next column, I'll cover the installation and configuration of JDBC and ODBC in more detail. Until then, I'd suggest the following IBM Redbooks for your reading pleasure: Porting Unix Applications Using AS/400 PASE (SG24-5970), Exploring NFS on AS/400 (SG24-2158), and the Redpiece Linux Integration with OS/400 (SG24-6551). These are available at the IBM Redbook Web site.
Barry Kline is a consultant living in central Pennsylvania. His interests include Linux integration, Java Web-based applications, and motorcycling--just not all three simultaneously. Barry can be reached at
LATEST COMMENTS
MC Press Online