iSeries to : First Contact In this three-part series, Thibault Dambrine describes the basics of the UNIX and first impressions, from the perspective of an iSeries programmer. • Part 1 describes the basics of UNIX, how it came to be and how the UNIX architecture differs from that of the iSeries. • Part 2 deals with some of the basic UNIX commands, directories, security and the scheduling system. • Part 3 is all about scripting, the UNIX equivalent of the iSeries’ CL language.

(Part II of III)

UNIX First Impressions Thibault Dambrine By Thibault Dambrine start with. One other common point with with the F4 key or any equivalent to DOS, the language (Korn OS/400 prompting in UNIX. n any situation where you try a new Shell, etc..) is interpreted, In a strange twist of fate, QSHELL, car, visit a new house, you get a few like a .bat of DOS . the UNIX style shell implemented on “first impressions” that will likely OS/400 has no F4 prompt key support remain in your mind for a while. In 2) UNIX commands have evolved from and no “man” command either. Again, Ithe next few paragraphs, I will describe many sources and many authors. They there will be more on this topic later in my first UNIX impressions. My aim is do NOT follow any type of naming the article. to convey what I saw, as a typical iSeries convention. This, for the OS/400 pro- programmer, when first crossing the line. grammer, is something to get used to. 4) Speaking of no iSeries-style F4 Here are 10 items that struck me in my It’s hard to compare commands like prompting, UNIX usually executes, first UNIX experience: “CRTCLPGM” – named after “CReaTe without warning, exactly what you tell ProGraM” with it to do. Expect no warnings if you are 1) Upon first glance, my number one “awk” named after “Aho, Weinberg, and about to do something completely silly. impression was that UNIX could be Kernighan” – the three authors of the Case in point: If you log-on as root, the probably well described as “MS DOS command. “awk”, by the way, is a text UNIX equivalent to the OS/400 QSEC- on steroids”. The command line behaves manipulation command. OFR profile, you can comfortably type the same way and it seems to be just as the following instruction: -rf /* friendly. UNIX can accommodate mul- 3) If you do become acquainted with and hit enter. tiple layers of directories (directories UNIX or Linux, or any of the flavors within directories) but it has no conve- in between, you will need to get used With this order, using that profile, nient way to represent or print the direc- to referring to “man” pages. The man UNIX will proceed to wipe out your tory structure (not even a DOS “tree” command (short for “manual”), coupled entire system, including the operat- equivalent). I subsequently found a with the command you are curious about, ing system without even as much shell script that could do that on the delivers manual pages (often referred as a burp or a thank you. For this Internet, which means it can be to as man pages) describing the use of reason, to protect yourself against done. It’s just not there the command. Most times, man pages dangerous experiments, it is best to for you to are cryptic and seldom have more than use the root user profile sparingly. minimum examples. There is no This of course, is one man’s opinion on prompting command prompting. There are devel- opers who the iSeries operating system too talkative for its own good, and that less verbose is better.

5) vi is the most well known editor on UNIX. If you know vi, you can be sure you know at least one editor on just about any Unix machine you will ever get to work on, save your trusty iSeries, who has chosen not to implement it in QSHELL. Pronounced “vee-eye”, vi is short for visual interface.

30 Toronto Users Group for Midrange Systems – May 2003 Toronto Users Group for Midrange Systems – May 2003 31 Working with three modes of operation: Octal Binary Permission Directory “command”, “insert” and “line editor”, vi Value Value Listing has over 100 commands. Entire books have been written about vi. My experi- 1 001 no read, no write, execute --x ence is that it is rather confusing until 2 010 no read, write, no execute -w- you figure out which mode you are in. 3 011 no read, write, execute -wx This is the type of editor you have to use 4 100 read, no write, no execute r-- regularly to get proficient. UNIX pros 5 101 read, no write, execute r-x swear by it. They often say it is the most 6 110 read, write, no execute rw- powerful text-based editor available. If 7 111 read, write, execute rwx you think there is power in simplicity, you may be tempted to argue differently. Table 1 My number one vi tip: stay away from the arrow keys on the right side of the key- Each file has 3 sets of “read/write/ The 0 to 7 values are actually used as board - they won’t move your cursor! execute” flags attached to it, one for the shortcuts, referring to their binary values. owner, one for the group and one for the For example, the binary value of Octal 5 6) Object authority or “file permission” public. These 3 flags can be set to 0 or 1. is “101”. This translates into a permis- in UNIX lingo, is something to both be To handle all this in the most economical sion value of “r-x” or “read, no write, aware of and get used to. I will go into way, each of the three authority groups execute”. Octal 6 translates into binary some detail here because this is a key are represented by the binary value of an “110” and thus the permission value concept. Understanding how permis- octal number. This Octal number, (0 to of “rw-“ or “read, write, no execute”. sions work in UNIX is a necessity for 7) translated into binary, gives a combi- Table 1 tells the whole story: every-day operations and it also gives nation of 3 binary digits. a good indication of the style in which If a file for example has permission set- UNIX works. Clear as mud? You need to understand ting 777, it really has permission setting that clearly when you where the owner has rwx (read/write/ work with UNIX, as execute), the group has rwx (read/write/ Directory Description this is one concept you execute) and the public has rwx (read/ / Root directory of the filesystem. will deal with every write/execute) permission. The permis- /bin/ User utilities fundamental to both single-user and multi-user day. If for example, you sion flags look like rwxrwxrwx, listed environments. write a small shell at the right side of the file in a directory script to see what you listing. /boot/ Programs and configuration files used during operating system bootstrap. can do, you will never be able to execute it If a file has permission setting 764, the /boot/defaults/ Default bootstrapping configuration files. unless you change the individual has rwx (read/write/execute), /dev/ Device nodes. permissions (using the group has rw- (read/write/no exe- /etc/ System configuration files and scripts. the obviously named cute), and the public has r-- (read/no /etc/defaults/ Default system configuration files. command) to write/no execute). The permission flags /etc/mail/ Configuration files for mail transport agents such as sendmail. give yourself permis- look like rwxrw-r--, listed at the right sion to execute the file. side of the file in a directory listing. /etc/namedb/ Named configuration files. You can see the permissions on the files /etc/periodic/ Scripts that are run daily, weekly, and monthly, via cron. A file, in UNIX can be in a directory by doing a –l com- /etc/ppp/ ppp (point-to-point) configuration . anything from a flat mand. /mnt/ Empty directory commonly used by system administrators as a file to a UNIX script. temporary mount point. A UNIX script with an There is more to read on UNIX permis- /proc/ Process file system “x” in the “execute” per- sions, but this is the base functionality. mission flag position Coming from the iSeries environment, Home directory for the root account. /root/ is deemed executable, this method of determining authority or /sbin/ System programs and administration utilities fundamental to both even if not compiled permissions, looks like a step backwards. single-user and multi-user environments. (shell script is inter- It is however widely used and accepted /stand/ Programs used in a standalone environment. preted). Each file has by UNIX lovers the world over. /tmp/ Temporary files, usually a memory-based filesystem (the contents 3 types of permissions There is no equivalent in UNIX to the of /tmp are usually NOT preserved across a system reboot). (read, write or execute), notion of “object security” in the OS/400 /usr/ The majority of user utilities and applications. for each of the three - sense. This may you to understand egories of users (indi- the somewhat simple UNIX permission /var/ Multi-purpose log, temporary, transient, and spool files. vidual users, groups of system. Table 2 users or all users).

30 Toronto Users Group for Midrange Systems – May 2003 Toronto Users Group for Midrange Systems – May 2003 31 7) One of the things you may have heard Perhaps the closest thing to a standard The shell, in UNIX, is more or less already about UNIX is that there is in UNIX available right now is the equivalent to the iSeries CL language. more than one standard for this operat- Linux kernel, which is standard across Just as there are many UNIX operating ing system. You heard the truth. The all distributions (Red Hat, SuSe etc.). system manufacturers, the main flavors of UNIX currently in the It is also evolving faster than all other has also evolved over time. S.R. Bourne market place are Berkeley UNIX, AT&T UNIX flavors and provides a lot more wrote the original UNIX shell around Systems V Release 4 , SunOS/Solaris, user friendly utilities than the traditional 1975. His version, one of the most XENIX, SCO and Linux. UNIX vendors. commonly available, is the “Bourne shell”. Bill Joy, from the University of The closest thing to a governing body 8) You may have heard of the term UNIX California in Berkeley, created the “C that says, “This is UNIX” is the POSIX “shell” before. “Shell” is a UNIX term shell”. David Korn, at AT&T, created standard. It is now an accepted fact that for the interface between the user and the “Korn shell”. Linux has something to be commercially viable, a UNIX the operating system. The shell is the called the “Bourne Again shell”, also system, of any flavor, has to be POSIX layer of programming that interprets and known as “”. Consistently, each compliant. That said, as long as this executes the commands a user enters. As new shell creator (or creators) have tried minimum is met, any company is free to the outer layer of an operating system, a to build upon established bases to create invent or come up with a newer, better shell can be contrasted with the kernel, a better shell. Note that the Linux bash and stronger version. This is good and the operating system’s inner most layer (Bourne Again shell) is free, as opposed bad at the same time, for obvious rea- or core of services. to the other shells. sons. It is good because there is freedom to innovate and change, it is bad because There are several UNIX shells. The 9) Despite differences between UNIX there is no strict standard, and thus main shells are Korn shell, C-shell and releases, some things are similar. Upon incompatibilities do creep in. Bourne shell. Why so many? delivery, most UNIX systems have a number of standard directories, which contain well-known utilities or contain operating system programs that will per- form certain functions or services. Table 2 gives a quick idea of what these are. Note that the slash (/) is the symbol for the root directory. If you do a “ /”, you are doing a “change directory to root”. This directory, in UNIX, is the OS/400 equivalent to QSYS, where all libraries ultimately belong. Note also that the example below is a typical map, but not necessarily an exact one for all UNIX flavors. On the iSeries, up until recently, we had only one level of library or direc- tor: There was QSYS, and all the libraries within it. This has now changed with the addition of the IFS, the Integrated File System, which allows multiple levels of directories.

© The 5th Wave, www.the5thwave.com Wave, 5th The © 10) In the same league as knowing what is going on with the authorities or permis- sions, there is a function in UNIX called the “cron”, or “crontab file”, which is equivalent to what we would call the “job scheduler” utility in OS/400. The crontab, you guessed it, is UNIX’s ver- sion of a task scheduler. At first glance, it is very cryptic, but it can be interpreted with relative ease if you know what it is talking about. Be prepared – in UNIX, “Relatively cryptic but can be interpreted” is practically a way of life.

32 Toronto Users Group for Midrange Systems – May 2003 Toronto Users Group for Midrange Systems – May 2003 33 This is how the entire operating system Example 1: Example 3: is built. Many UNIX programmers will 0 * * * * /etc/dothis.abc 21 14 * * 2 /yellow/brick/ tell you that this is where the power is. This means literally “execute the script road/wizard.exe Like beer, this may be an acquired taste, located at /etc/dothis.abc” whenever This example sets a crontab entry to run popular but acquired. the clock is equal to 0 minutes o n only on Tuesday at 2:21 PM. Note that this ANYDAY, ANY HOUR, ANY is written in military style time, i.e. 14:21. Back to the topic. A crontab file DAY-OF-MONTH, ANY can have any number of commands, DAY-OF-WEEK. So the In the next issue (Part III), I will explore although it can only process one script is set to run ONCE more details regarding UNIX Shell command per line. One more thing to PER HOUR EXACTLY Scripting, and in particular the remark- remember: after the last command, you ON THE HOUR regard- able iSeries QSHELL environment. must have a blank line or the crontab less of what day it is or T

What does a crontab line look like? Example 2: Thibault Dambrine works as an inde- The way the schedule looks is very 0 0 * * * /etc/dothat.now pendent contractor in Calgary, Alberta. cryptic but it’s really very simple. There This is a little more picky. This crontab You can visit the iSeries / AS/400 are five fields to the schedule. They are runs again whenever the internal clock related website he manages at http:// noted in bold below: hits ZERO (0) Minutes, but instead of www.tylogix.com or e-mail him directly running once per minute it will only at [email protected]. MINUTE(0-59) HOUR(0-23) DAY-OF- run once per day. Why? Because we The author disclaims all warranties, whether MONTH(1-31) MONTH-OF-YEAR(1- also set the HOUR to zero so both the express or implied, including, but not limited to, 12) DAY-OF-WEEK(0-6) Note: 0 = MINUTE and the HOUR must be equal the implied warranties of merchantability and fit- Sunday. Also note that the ASTERISK to zero before crontab will execute /etc/ ness for a particular purpose. Any trademarks and (*) stands for a WILDCARD meaning it dothat.now. So this example runs once product or brand names referenced in this docu- will match any value. per day at midnight, server time. ment are the property of their respective owners.

32 Toronto Users Group for Midrange Systems – May 2003 Toronto Users Group for Midrange Systems – May 2003 33