Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

Writing SQL Reports PP

VIEWS: 15 PAGES: 40

									   Introduction to UNIX


         Mike Baranski
      mike@secmgmt.com
Security Management Consulting
   http://www.secmgmt.com/
             Objectives
 Learn the basics of UNIX filesystems
 Basic usage via command line utilities
 Editing files via a terminal session
 Picture Perfect utilities via the command
  line
 Advanced scripting utilities
           Section 1

HISTORY OF UNIX
    1969 AT&T BELL LABS
 Originally open source, used by research
  institutions, governments, and computer
  companies
 By 1987 there were over 500,000 UNIX
  installations around the world
 The system was “open”, and the
  implementations were diverging
               POSIX.1
 1988 POSIX.1 was published as a standard
 Published by Open Software Foundation
  (OSF) and UNIX international (UI)
 This made programs that were developed
  for UNIX “portable”
 Some versions were “open source”, some
  were not
 RedHat is an “open source” system, IBM‟s
  AIX is not
       2009 AND BEYOND
 UNIX market $69 billion in 2008, projected
  to be 73 billion in 2013
 UNIX is widely supported by large and
  small corporations
 UNIX systems must meet POSIX standards,
  but can (and do) go above and beyond
             Section 2

LOGGING IN
     MULTI-USER SYSTEM
 UNIX is a Multi-user system
 Multi-user means concurrent access for
  many users
 Different user accounts have different levels
  of access to utilities
 “root” is the “super user”, and other
  permissions vary
 Some accounts are just process accounts
  and cannot log in
    SSH/TELNET AND PUTTY
 Telnet is an un-encrypted protocol to log
  into a terminal session
 Secure Shell (SSH) is like Telnet, but
  encrypted
 Using SSH is preferred
 Telnet transfers username/password and
  data in clear text, and a network sniffer can
  easily compromise a system
              SSH KEYS
 SSH supports 2 methods of authentication
 Username/password authentication prompts
  the user at the time of login
 SSH can also use keys to authenticate
  without a password
 This is useful for automated processes that
  are scheduled and need to copy files, run
  commands on remote systems, etc.
    SSH KEYS AND PUTTY
 Putty can use SSH keys to login to a system
  without a password
 The ppug.org site has a step-by-step tutorial
  on how to install the keys on a Picture
  Perfect system and a Windows system
  running Putty
 Be careful with SSH keys, they allow
  access without knowing a password
    LOGGING IN WITH PUTTY
 Launch Putty
 Enter hostname and connect with username
  and password
 When you are logged in, you are in your
  “home” directory
 Everyone‟s home directory can be different,
  and have different permissions
              PERMISSIONS
   UNIX permissions have 3 different
    “groups”
    – Owner
    – Group
    – Everybody
   Each “group” has 3 different “bits”
    – Read
    – Write
    – Execute
          PERMISSIONS
 Permissions are managed with the “chmod”
  command
 “chmod” can be used to add or remove
  permissions
 Example: “chmod +x hello.sh”
 Example: “chmod –x hello.sh
       DOCUMENTATION
 “man” displays manual pages
 “man chmod” shows the manual page for
  chmod
 “man” exists for almost every command in
  the system
 Google is usually more efficient
       UNIX FILESYSTEMS
 Unix does not use the “drive” convention
 The “root” filesystem is represented by “/”
  (not to be confused by /root)
 Off of “/”, we can have either directories or
  other “filesystems”
 Filesystems can be partitions on any disk,
  and do not have to be directly off of the “/”
  directory
      UNIX FILESYSTEMS
 “dmesg | grep hd” shows installed hard
  drives
 The “df” command shows disk usage, and
  filesystem information
 grep will be discussed in more detail later
 Some systems can use “df –h” to make the
  block sizes human readable
        MOVING AROUND
 “cd” can be used to change directories
 “pwd” shows the current working directory
 Relative versus Absolute is important
 Relative starts with a ., Absolute starts from
  “/”, or root
 “cd /tmp” makes your current working
  directory “/tmp”
 Similar to c:\temp on a windows system
       LOOKING AROUND
 “ls” lists files
 “ls –a” lists all files
 Files that start with a “.” are hidden
 “.” is the current directory, “..” is the
  directory above, “../..” is 2 directories
  above, etc
 “ls –al” is a “long” listing that shows more
  information (size, owner, group, etc)
    NETWORK INFORMATION
 ifconfig shows network adapter information
 The loopback interface is common to all
  systems (127.0.0.1)
 192.168.x.y is a reserved address space
 IP addresses are like phone numbers
 DNS is like the phone book
 /etc/hosts stores local host information, and
  can override DNS
          EDITING FILES
 The Visual Editor (vi) is on every unix
  system
 vi uses “modes”, edit mode and command
  mode
 Command mode is the default mode
 Edit mode can be invoked in many different
  ways
 The esc key goes from edit mode to
  command mode
           EDITING FILES
 The arrow keys navigate through the file
 A capitol G moves to the end of the file
  (while in command mode)
 :0 moves to the top of a file (when in
  command mode)
 i invokes insert mode in vi
 After editing in insert mode, press esc to
  invoke command mode
           EDITING FILES
 :w writes a file (in command mode)
 :q quits vi
 :q! quits vi without saving
 When in doubt, esq -> :q! will quit and
  discard edits that were made
 vi can be a pain, but it pays to know it
  because it is on every system
      MORE ABOUT GREP
 grep is used to search files or output from a
  command
 grep “192” /etc/hosts shows any line in the
  host file
 man grep to see all of the options, it is a
  very powerful command
                  PIPES
 Pipes (|) can be used to pipe output from
  one command to another
 Grep is a good example of a command that
  is useful to use with pipes
 ls –al | grep sql lists files that match the
  pattern
 Pipes take the output of the command on
  the left and passes it to the command on the
  right
         Output redirection
 Each process has 2 different output
  “streams”
 Standard out and Standard error (stdout and
  stderr)
 Either or both of these can be redirected
  with > and >>
 > truncates the target file, and >> appends
          MORE ON UNIX
 UNIX is made up of many small utilities
 Do one thing, and do it well
 Using pipes, these small utilities can be tied
  together into powerful scripts
 http://mally.stanford.edu/~sr/computing/bas
  ic-unix.html
 This is a good list of commands and what
  they do
 Man pages are your friend
          Section 3

INFORMIX AND CASI TOOLS
        INFORMIX TOOLS
 Informix provides a number of tools to get
  information
 CASI also provides tools to import and
  export data
 dbaccess is the Informix tool to get system
  information from the command line
 „dbaccess proteus‟ will start a session and
  open the informix database
        INFORMIX TOOLS
 Dbaccess can also be used with pipes
 Not all of the CASI tools support all of the
  Informix syntax
 Particularly useful is the “unload to” SQL
  command
 “unload to „/tmp/category.psv‟ select * from
  category”
 This creates a pipe separated file in /tmp
            CASI TOOLS
 The CASI tools are mainly small command
  line reporting utilities
 Sqlstmt takes an SQL statement and runs it
 Sqlstmt “unload to „/tmp/category.psv‟
  select * from category”
 This SQL is not supported by sqlstmt
 finderr 201 shows the error message
        INFORMIX TOOLS
 echo “unload to „/tmp/category.psv‟ select *
  from category” | dbaccess proteus
 This writes all rows from the select into a
  pipe separated file: /tmp/category.psv
 Dbaccess supports the full range of
  Informix syntax
 If a valid statement does not work with
  sqlstmt or selectit, it should work with
  dbaccess
             MORE ON VI
 To convert the file we just unloaded to to a
  csv file (to import into Excel, for example)
 Open the file with vi
 To do a global replacement, type:
  “:%s/|/,/g” to do the substution
 Type “:w /tmp/categories.csv” to save the
  csv file
 It can now be imported into Excel and
  manipulated
        INFORMIX TOOLS
 “load from „/tmp/category.psv‟ insert into
  category” does the opposite of unload to
 If the category table is empty, “load from”
  will insert the rows into the category table
 Echo “load from „/tmp/category.psv‟ insert
  into category” | dbaccess proteus
 This will reload the category table into the
  system
             CASI TOOLS
 selectit, selectout, selectrpt, and query are
  all tools to query the database
 The CASI import/export manual documents
  these utilities
 They are useful for quickly looking things
  up without logging into the user interface
 Use caution with sqlstmt (and dbaccess)
  because damage can be done
               ONSTAT
 Onstat has many options, and can show just
  about any information from the system
 Onstat –d shows used/free informix space
 Onstat –g sql shows running sql queries
 The session id can show what statement is
  running
 Onstat –g sql xyza
       RAW FILESYSTEMS
 Raw filesystems are not formatted or
  managed by the OS
 Informix has its own proprietary file format
 A raw filesystem allocates space, but does
  not format it
 Informix manages it‟s own I/O with the
  filesystem
 This information does not show up with df
      RAW FILESYSTEMS
 The PP installation script handles creating
  the raw filesystems
 There is no way to look at a raw filesystem,
  Informix must read and “decode” the bits on
  the disk
 Raw filesystems should not ever be written
  to
               ONMODE
 Onmode is be used to start and stop
  Informix
 The PP startup/shutdown process calls
  onmode
 Onmode can also be used to kill a session
 Find the session id with onstat
 Onmode –z xyza kills the process
 This is useful for bad queries that are
  overloading the system
         THE END

QUESTIONS OR COMMENTS?

								
To top