Sunday, 11 June 2017

Unix Crib Sheet

Unix vs. Windows Crib Sheet


Purpose

This document is intended to assist those who are more familiar with a Windows environment in transitioning to a Unix AIX environment. It should be considered a living document and additions/amendments are welcomed from anyone who has further information or better ways of accomplishing a task.

Accessing the System

Unless you have direct console access to the machine you will need to control it remotely. Whereas with windows you may be used to using tools such as remote desktop or terminal services to access a server, with a Unix server you will need to use telnet or SSH to logon to the server remotely.

Using Telnet


At the command prompt or in the run window type: telnet <computer address>
e.g. telnet 10.3.1.12

Then a login prompt should appear into which you can enter your login name and password


When you have finished using telnet type exit to leave the program.

Using SSH

While Telnet can be appropriate to use when you are operating behind a firewall, SSH should always be used on an open network and can be used anywhere. SSH encrypts all data transferred to the server, including your password, unlike the older telnet protocol.

The easiest way to use SSH is to download the SSH version of PuTTY from http://www.chiark.greenend.org.uk/%7Esgtatham/putty/download.html

PuTTY is a windows client to which allows you to access a remote Unix machine via SSH (or Telnet or Rlogin). It also has various options which can help you use the command line interface more effectively. The complete documentation is available at:


General


-          AIX is case-sensitive.  Best practice is to keep all filenames in lower-case
-          AIX commands take switches and the switches must be listed directly after the command
-          Use Escape K (Esc + K) to repeat the previous command
-          Use history –n to list the previous n commands.  Each command will have a unique id listed.  You can then repeat one of these commands by entering r <id> where <id> is the unique id
-          Previously entered commands can be retrieved by pressing the Up arrow. For example, to retrieve the last but one command entered press the Up arrow twice
-          Use Date to display or set the date or time
-          Whoami – The command that displays who you are logged in as.

Cron Jobs

Cron jobs are time based commands often used to trigger shell scripts to perform actions at a particular time, similar to scheduled tasks in windows.

crontab – l >> filename  - This will export the cron jobs to a file, if the filename is not specifiec (crontab –l)  the list of files will be displayed on the standard output e.g. the screen.

crontab <filename> - This will import the cron jobs from a file. The crontab can also be edited on screen but it is simpler to modify the cron jobs in file format.


Memory and Disk Usage

-          To monitor memory usage enter ps aux | grep -v "PID %CPU %MEM"| grep -v kproc |sort +5 -rn | head -n 15

-       du –am /Siebel/siebsrvr | sort –rn > filesizes.txt – Will output the file sizes sorted by largest first for all files/folder under the /Siebel/siebsrvr tree to a filename filesizes.txt.  This is useful to work out which files are consuming the most disk space.


Help


man <command> – Will describe what the command does, its switches and examples of how to use it

Navigating


ls – Will display a list of all files and directories in your current location. Use switch –l to see results in a list, the list will display date modified and read\write access permissions as well as the file name.

cd – Will change your current directory: cd /Siebel/siebfile will take you to the Siebel directory siebfile subdirectory (N.B. / indicates a directory in Unix rather than \)

. - . indicates your current location .. indicates the parent directory therefore cd .. will take you up one level in a directory tree to the parent directory.

* - Is a wildcard indicating one or more characters. This can be used with cd to save the amount of typing where there is only one directory of a similar name. e.g. cd /

pwd – Will print out the current working directory / show your current location

 File Management


cp – Will copy a file from one location to another. You can use the –r option to recursively copy files, i.e. copy whole directory structures. This can be used along with wildcards to copy all files of a certain name:
cp df1.txt ./exampleA (Will copy the file named df1.txt in the current location to the sub-directory named exampleA)
cp –r ./exampleA  ./exampleB (Will copy the directory named exampleA including all files and sub-directories to a directory named exampleB)
cp ./exampleA/df* ./exampleB (Will copy all files in the directory exampleA whose names begin with df to the directory exampleB)

scp - Allows you to secure copy files between servers on the same network. Generally, if you can ping the IP address of the destination machine from the source machine you should be able to secure copy between them.

scp filename username@ip_address:/destination_path

eg. scp in_fr_par.txt sadmin@10.128.7.143:/siebel/siebfile/migration/mig_files/mig_fr_files

You will then be prompted for the user’s password.

A status bar will indicate progress of the copy.


mv – Will move a file from one location to another. As with copy but the source file will not remain. This can also be used for renaming a file.

mkdir – Will make a new directory with the provided name: mkdir exampleA will create a new directory in the current location with the name exampleA

chmod – Sets permissions on the file/folder.  E.g. chmod 777 give R/W/E access to all

cat – Concatenates multiple files into a single file or other output:
cat df1.txt df2.txt > dfall.txt (Combines files df1.txt and df2.txt into a new file dfall.txt)

rm  - Removes /Deletes files
            rm df1.txt (Deletes the file df1.txt)
            rm  df*.txt (Deletes text files beginning with df)
rm –r ./exampleA (Deletes the directory exampleA and all it’s contents – USE WITH CAUTION)

rmdirRemoves empty directories

Finding Data

To search files for a particular string you can use the “grep” command. This has the following format:
            grep search_string filename
e.g grep error *.log
will return any line containing the word “error” in a file with a name ending in .log. If the string being searched for contains spaces then you need to put double quote marks ound the string

the grep command only searches in the current directory. In order to search subdirectories you need to combine a find command with grep e.g.
            find . -name *.log | xargs grep error

the grep command normally returns just the line from the file where the data is found. However, it is possible to extract more data than this using e “-p” switch (p = paragraph). This switch determines the character(s) that mark the start and end of any line or paragraph. An example of how this might be useful is as follows:
o   If you have an XML file with a number of different entities but you want to find some data that exists within a specific tag (such as <activity>… </activity> ) and then write the complete tag and its contents out to the file, you could use the following command:
grep -s -p"activity>" search_string filename >> out_filename

Saving Results to a File

If you run a command then the results are normally displayed on the screen; however the results can be saved to a file using either the “>” command or the “>>” command.
“>” creates a new file (deleting any existing file with the same name whereas “>>” appends to the file (or creates it if it does not exist) e.g.
            grep search_string filename > out_filename
            grep search_string filename >> out_filename


Compressing and Transferring Files

It is a common requirement to have to download files from the UNIX server to your local pc where they can be more easily examined. Such transfers can be done via the ftp command line program or by using a specialist program such as SmartFTP which can be downloaded from http://www.smartftp.com/ which provides a GUI for the transfer of files.

The time taken for such transfers can be vastly reduced by compressing the file on the Unix server before transfer.

tar – The tar command can be used to create a single file which contains a collection of files

tar cvvf dffile.tar df1.txt (Would create a tar file containing the df1.txt file)

tar cvvf log.tar *.log (Would create a single file named log.tar containing all files in the current directory with the suffix .log)

gzip – Compresses files (similar to winzip)

            gzip -c dffile.tar > dffile.gz (would compress the tar file created previously)

gunzip – Uncompresses files (similar to winzip)

gunzip -c dffile.gz > dffile.tar (would uncompress the previously compressed file)

More information on tar, gzip and gunzip can be found at :

Siebel on Unix


File Structure:


In the typical Windows siebsrvr installation, the log, archive, objects directories etc. are situated directly within the siebsrvr directory. In Unix such directories should be accessed from

siebsrvr\enterprises\<enterprise_name>\<server_name>

This can be confusing as these directories can also be found at the siebsrvr level.

Setting Environment Variables

Before using the command line srvrmgr program or starting and stopping Siebel servers, you must ensure that the environment variables are correctly set.

In the siebsrvr directory type . ./siebenv.sh

Starting and Stopping Siebel Processes


When you are starting and stopping processes you can type:

ps –ef | grep sadmin

This will list all processes running under sadmin, so that you can see whether or not the services are running. ps –ef | grep root can be used to check for processes running under root which may in some environments include the web processes.

Siebel Server
In the siebsrvr/bin directory type:

To Stop:                      stop_server ALL
To Start:                      start_server ALL

Siebel Gateway
In the gtwysrvr/bin directory type:

To Stop:                      stop_ns
To Start:                      start_ns
To View:                     list_ns

Web Server
In the sweapp/bin directory type:

To Stop:                      . ./stopaps
To Start:                      . ./startapa



References



We also have a copy of the very useful UNIX in a Nutshell on the bookshelf in the small meeting room in the London office.



No comments:

Post a Comment