Monday, March 08, 2010

Unix Interview Questions

1)I know the name of a UNIX command, but I don't know what it does?
Use the 'whatis' command
whatis will give a brief description of the command
Example:
$ whatis grep
grep grep (1) - search a file for a pattern
2)I know what a UNIX command does, but I can't remember the name?
Use 'man -k'
This will do a keyword search of the man pages
Example:
$ man -k grep
egrep egrep (1) - search a file for a pattern using full regular expressions

fgrep fgrep (1) - search a file for a character string
fmlgrep fmlgrep (1f) - search a file for a pattern
grep grep (1) - search a file for a pattern
nisgrep nismatch (1) - utilities for searching NIS+ tables
3)What are .o files? .a files?

When a programmer writes a program, he begins by writing the code in a programming language. This 'source code' is kept in a text file. When he is ready to build the program, he runs the source code text through a compiler. This translates the source code into 'object code'. Object code is in a format that is understandable by the machine. ('Machine language') Note that object code is not portable across platforms. The same source code compiled on a Solaris machine will produce a different .o file when compiled on a HP-UX machine. All object files (.o, .a, .so) cannot be copied across different platforms.



When all the object code is compiled, the programmer next collects all the object files, and runs them through the linker. The linker basically collects all the object code, along with any other necessary code, and produces an executable (or 'binary') Object code can also be collected into a library file, or archive. (.a file) This file is created by the 'ar' command. It just collects all the object code into one file, and adds a table of contents to it. Library files can be linked into an executable the same way as .o files. Oracle delivers its code (except for the NT platform) as .o or .a files. These files are run through the linker to produce executables.

4)What are .so files?
.so files contain object code like .a and .o files. However, these libraries are not linked in when the programmer creates the executable. Instead, they are loaded in when the program runs. This allows the library to be shared among multiple programs, hence the name 'shared libraries' (on Windows, these are called DLLs) If a program cannot find the shared libraries it needs, it will not run. See also the questions on ldd and LD_LIBRARY_PATH.

5)How do I tell an HP10.20 object file from an HP11.0 object file?
The preferred way to tell whether an object was built with HP-UX 10.20 or HP-UX 11.0 is use the odump command.

odump -comp The -comp switch will give you the flags with which the object was compiled as will as the revision. The revision number for objects built with 10.x will appear as "A.10.xx" where xx is dependent on the exact revision and patch level. For 11.0 objects, the revision number will appear as "A.11.xx". 6)What is the best way to kill a process? First, use ps to get the process id (PID) Try using: kill This will give the process a chance to clean up after itself, like removing temp files, etc. Some processes will not accept or ignore this signal. If the process does not go away, use: kill -9 This signal cannot be ignored; it will definitely kill the process. The process will not have a chance to clean up after itself though. Use kill -9 only if necessary. Note that you must be the process owner or the superuser to kill a process. 7)How do I get the value of SHMMAX? Solaris: use 'sysdef | grep SHMMAX' HP-UX: use 'grep SHMMAX /usr/conf/master.d/core-hpux' 8)I want to eject the cdrom, but it says it is busy. How do I find who has it locked? Use the 'fuser' command Type: fuser -u /cdrom (or whatever mount point the cdrom is on) This will give a process ID, followed by a letter The letter 'c' indicates this process is using the /cdrom directory as it's current directory From the process id, you should be able to find the user 9)I'm trying to uncompress a file that I know is in this directory, but it keeps telling me the file cannot be found? Make sure the file has an extension of .Z (capital Z). Uncompress will try to add the extension if it does not have it and you will get something like this: $ uncompress 504305t.z 504305t.z.Z: No such file or directory 10)How do I remove a file that begins with a hyphen? (Like -filename) rm will normally complain about an invalid option if you say: rm -filename Most UNIX commands will bhave this way, treating the characters after the hyphen as an option. rm has an option to say 'end of options, the next parameter is a filename' The option is '--' (double hyphen) So you can use: rm -- -filename Most UNIX commands have a -- option like this to signify end of options. 11)My Escape key does not work in vi? Help! Go to your NCD boot server machine (orlsun1, 2, 10, or 11) There should be a file called 'xh' in your home directory. Add these two lines to the file: /usr/openwin/bin/xmodmap -e 'keycode 9 = grave asciitilde' & /usr/openwin /bin/xmodmap -e 'keycode 14 = Escape' & Reboot your NCD. Now, the ~ key (at the top left of the keyboard) is now the Escape key. The ~ and ` are on the key between the Shift key and Z. (Control-[ also works as Escape) Shell Program – UNIX Unix shell script is nothing but a collection of unix commands written as a block to be executed sequentially Simple Commands: ls; grep; cut; cat 12)Where to get the list of commands: /usr/bin Help about these commands: man Accessing shell scripts from Oracle Apps 13)What can be done using a shell script To call a sql*loader script, to call a sql*plus program, to do an FTP, send email with attachment, submit a concurrent program…. FILENAME=$APPLCSF/out/arjnltrx.out ATTACHMENT=arjnltrx SUBJECT="Receivables Posting“ RECIPIENT= amudhan@crm.hcltech.com CARBONS= srini@crm.hcltech.com DATE=`date` if test -f $FILENAME then uuencode "$FILENAME" "$ATTACHMENT"|mailx -s "$SUBJECT" -c "$CARBONS" "$RECIPIENT"; chown applfin:dba $FILENAME Else echo "No new file on $DATE"|mailx -c "$CARBONS" "$RECIPIENT“ fi ret_val=`CONCSUB apps/apps SQLAP 'Payables Manager' AMANICKA WAIT=Y CONCURRENT SQLAP APXINRIR America Standard " " BWEBB '10-JAN-2001' 10-JAN-2001' 'Jan-01' 'No' 'No'` request_id=`echo $ret_val | cut -d ' ' -f3` status=`sqlplus -s apps/apps < /tmp/tempfile1
cut -d"~" -f1,2,3,4,6,7,8,9,10,11,12 /tmp/tempfile1 > $FILENAME.dat
}
load_work_table()
{
sqlldr -s userid=$LOGINID control=$ldrctl log=$ldrlog data=$FILENAME.dat bad=$ldrbad discard=$ldrdis
# Copy loader log file to the Concurrent request log file
echo "Loaded log for file : $FILENAME" >> $C_CS_TOP/log/l$REQID.req
cat $ldrlog >> $C_CS_TOP/log/l$REQID.req echo " “
}
load_file()
{
prepare_file;
if [ -s $FILENAME.dat ]; then
load_work_table;
fi
}

# MAIN Processing starts here

inputstring=$1
set_environment;
echo "Execution Timestamp $timestamp "
for FILENAME in `ls $indir/in`
do
echo "Processing file : $FILENAME"
load_file
Done

echo "Program complete“
exit 0

Use the following format to create the header section
#!/bin/sh
#
# NAME
# AUTHOR
# MODIFICATION HISTORY
# SYNOPSIS
# DESCRIPTION
# RETURN VALUE
#######################################

Test the status of command execution as a condition for proceeding. Use the $? variable to test for for zero (success). For ex: $? = 0 is success.

Use the exit command with a exit status code to end the shell script. Use exit 0 for success and exit 1 for error

Make the script executable. Change the permissions of the file to user and group read and execute (chmod 550).




No comments:

Post a Comment