Arquivo da tag: Shell

What is the KornShell Language?

The KornShell language was designed and developed by David G. Korn at AT&T Bell Laboratories. It is an interactive command language that provides access to the UNIX system and to many other systems, on the many different computers and workstations on which it is implemented. The KornShell language is also a complete, powerful, high-level programming language for writing applications, often more easily and quickly than with other high-level languages. This makes it especially suitable for prototyping. There are two other widely used shells, the Bourne shell developed by Steven Bourne at AT&T Bell Laboratories, and the C shell developed by Bill Joy at the University of California. ksh has the best features of both, plus many new features of its own. Thus ksh can do much to enhance your productivity and the quality of your work, both in interacting with the system, and in programming. ksh programs are easier to write, and are more concise and readable than programs written in a lower level language such as C.

How to make a jar file run on startup & and when you log out?

//askubuntu.com/questions/99232/how-to-make-a-jar-file-run-on-startup-and-when-you-log-out

Here’s a easy way to do that using SysVInit. Instructions:

  1. Create the start and the stop script of your application. Put it on some directory, in our example is:
    • Start Script: /usr/local/bin/myapp-start.sh
    • Stop Script: /usr/local/bin/myapp-stop.sh

    Each one will provide the instructions to run/stop the app. For instance the myapp-start.shcontent can be as simple as the following:

    <code><span class="pun">#!/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash

    java </span><span class="pun">-</span><span class="pln">jar myapp</span><span class="pun">.</span><span class="pln">jar </span></code>

    For the stop script it can be something like this:

    <code><span class="pun">#!/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash
    </span><span class="pun">#</span> <span class="typ">Grabs</span><span class="pln"> and kill a process from the pidlist that has the word myapp

    pid</span><span class="pun">=`</span><span class="pln">ps aux </span><span class="pun">|</span><span class="pln"> grep myapp </span><span class="pun">|</span><span class="pln"> awk </span><span class="str">'{print $2}'</span><span class="pun">`</span><span class="pln">
    kill </span><span class="pun">-</span><span class="lit">9</span><span class="pln"> $pid</span></code>
  2. Create the following script (myscript) and put it on /etc/init.d.

    /etc/init.d/myscript content:

    <code><span class="pun">#!/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash
    </span><span class="pun">#</span> <span class="typ">MyApp</span>
    <span class="pun">#</span>
    <span class="pun">#</span><span class="pln"> description</span><span class="pun">:</span><span class="pln"> bla bla

    </span><span class="kwd">case</span><span class="pln"> $1 in
        start</span><span class="pun">)</span>
            <span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">myapp</span><span class="pun">-</span><span class="pln">start</span><span class="pun">.</span><span class="pln">sh
        </span><span class="pun">;;</span><span class="pln">
        stop</span><span class="pun">)</span>
            <span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">myapp</span><span class="pun">-</span><span class="pln">stop</span><span class="pun">.</span><span class="pln">sh
        </span><span class="pun">;;</span><span class="pln">
        restart</span><span class="pun">)</span>
            <span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">myapp</span><span class="pun">-</span><span class="pln">stop</span><span class="pun">.</span><span class="pln">sh
            </span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">myapp</span><span class="pun">-</span><span class="pln">start</span><span class="pun">.</span><span class="pln">sh
        </span><span class="pun">;;</span><span class="pln">
    esac
    exit </span><span class="lit">0</span></code>
  3. Put the script to start with the system (using SysV). Just run the following command (as root):
    <code><span class="pln">update</span><span class="pun">-</span><span class="pln">rc</span><span class="pun">.</span><span class="pln">d myscript defaults </span></code>

PS: I know that Upstart is great and bla bla, but I preffer the old SysV init system.