JANOS Help System: [Commands] [Topics] [Tech Support] [Printable Manual] [Search]
ADVANCED User Commands DESCRIPTION Beginning with JANOS v2.4 multiple commands may be executed from a single command line. While this may seem like a trivial convenience the ability to 'pipe' the output of one command into another can be very useful. These enhancements are intended to make the JANOS command line consistent with terminal and command line features in other operating systems. Previously there had only been the ability to save the output of any command into a file. For example the following would format a JSON file and save the result in a text file for later viewing/printing. cat -j manifest.json > manifest.txt With the recent command extensions the CAT command has been expanded to process any number of files in order. In this example you can create a single log file stretching back to include even the backup log content. cat jniorsys.log.bak jniorsys.log > syslog.log And with earlier versions of JANOS the only other command suffix of note was the ampersand '&' which instructs that the command be executed in the background. This would start the command in another command process and return you immediately to the command prompt. With JANOS v2.5 we introduce wildcards in the CAT command. The example above that combines the backup BAK and current LOG files can be abbreviated now as follows. Notice here that we pipe the result to the MORE command which opens the editor in read-only mode. You can then scroll, page and search the combined syslog log file content. cat jniorsys.log* | more Files matching the wildcard specification are concatenated in last modification date order. If that is not appropriate then you will need to specify those files separately in the order required. MULTIPLE COMMAND EXECUTION The semicolon ';' character can be used to separate two or more individual commands entered on the same command line. The utility in this varies but often we do execute a couple of commands in sequence and it might be simpler for us to enter them now and not have to wait for the first command to complete before getting to type the next. This also adds the combined commands to our command history letting us repeat the combination easily. JANOS now supports conditional command execution using the '&&' (logical AND) and '||' (logical OR) syntaxes. These are used to separate individual commands as you would with the semicolon ';'. The conditional aspect comes from the implied logical function. For an AND operation to be TRUE both operands must be TRUE. In the command line context a successful command is considered to be TRUE while a failed command is FALSE. So with two commands coupled with the '&&' separator if the first command fails (FALSE) the whole line is then going to be FALSE and there is NO NEED to execute the second command. JANOS won't bother. Similarly using the OR operation. With two commands coupled with the '||' separator if the first command is successful (TRUE) there is NO NEED to execute the second. No matter what happens with the second command the command line will be TRUE. So JANOS will not execute the second command. Again, the utility of these features is greatly dependent on your creativity. There are situations where this can be very useful. They have been implemented for the most part to support compatibility with other terminal and command line implementations in an effort to support users/programmers who have grown accustomed to such things. PIPING The vertical bar '|' character is used to indicate the desire to 'pipe' the output of one command into another. Many of the commands that process the content of a file now detect and can use as a source the data being passed from a previous command. The usefulness in this depends greatly on what you need at the time. For example you might want to know how many lines there are in the logs. Here we will use the GREP command whose -C option reports the number of matched lines. On the command line we execute the following command: bruce_dev /> cat jniorboot.log.bak jniorboot.log | grep -c 1285 lines matched Here the CAT command combines the full extent of boot logs and we then asks the GREP command to count the lines. To find out how many individual reboots are contained in the logs we merely take advantage of the GREP search string. bruce_dev /> cat jniorboot.log* | grep -c POR 37 lines matched TIP The CAT command extension that allows use of the wildcard specification, combines all matching files in order of modification date from oldest to latest. In this case combining LOG files exactly as in the previous example. We have the logs from the past 37 boot events. Here is another example command designed to list the last 2 times the clock has been synchronized. cat jniorsys.log* | grep NTP | tail 2 This is an advanced command which harvests the IP addresses of pool.ntp.org NTP servers reported in the jniorsys.log file pinging each to get a feeling for their response times. egrep sync.+(\\d+\\.\\d+\\.\\d+\\.\\d+) jniorsys.log -f "@ping -qc 1 $1" | exec This uses EGREP to locate the IP address and format a PING command for each. The PING command is to issue one and only one PING for the IP address. The piped output then appears like a batch file containing a list of PING commands and EXEC goes ahead and executes the batch. Here are some results from this: Reply from 207.244.103.95 (22ms) Reply from 162.159.200.123 (21ms) Reply from 44.190.5.123 (71ms) Reply from 65.19.142.137 (73ms) Reply from 142.202.190.19 (68ms) Reply from 66.151.147.38 (78ms) It is important to note that we are not passing data from one command to be used as keyboard input to the next. JANOS does not support the ability to source keyboard input from a file. For example using '< file' after a command. SEE ALSO HELP Topics: CAT, GREP, TAIL, EGREP, PING, EXEC, REGEX [/flash/manpages/manpages.hlp:2263]