TUG Eserver Magazine Volume 18 Number 5
Total Page:16
File Type:pdf, Size:1020Kb
iSeries to UNIX: First Contact In this three-part series, Thibault Dambrine describes the basics of the UNIX Operating System 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 shell 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 Shell Script language (Korn OS/400 command prompting in UNIX. n any situation where you try a new Shell, Bourne Shell etc..) is interpreted, In a strange twist of fate, QSHELL, car, visit a new house, you get a few like a .bat type of DOS file. 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 Control Language 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: rm -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 find 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 test 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. chmod 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 ls –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 cat- sense. This may help 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.