Saturday, April 13, 2013

Nitheen Kumar

Shell Scripting Interview Questions 3

 
21: I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?

We can use tail –f filename . This will cause only the default last 10 lines to be displayed on std o/p which continuously shows the updating part of the file.

22: I want to connect to a remote server and execute some commands, how can I achieve this?

We can use telnet to do this: telnet hostname –l user >Enter password >Write the command to execute  >quit

23: I have 2 files and I want to print the records which are common to both.?

We can use “comm” command as follows: comm -12 file1 file2 … 12 will suppress the content which are unique to 1st and 2nd file respectively.

24: Write a script to print the first 10 elemenst of Fibonacci series.?

#!/bin/sh a=1 b=1 echo $a echo $b for I in 1 2 3 4 5 6 7 8 do c=a b=$a b=$(($a+$c)) echo $b done

25: How will you connect to a database server from linux?

We can use isql utility that comes with open client driver as follows: isql –S serverName –U username –P password

26: What are the 3 standard streams in Linux?

0 – Standard Input 1 – Standard Output 2 – Standard Error

27: I want to read all input to the command from file1 direct all output to file2 and error to file 3, how can I achieve this?

command file2 2>file3

28: What will happen to my current process when I execute a command using exec?

“exec” overlays the newly forked process on the current process ; so when I execute the command using exec, the command gets executed on the current shell without creating any new processes. Eg: Executing “exec ls” on command prompt will execute ls and once ls exits, the process will shut down 

29: How will you emulate wc –l using awk?

awk ‘END {print NR} fileName’

30: Given a file find the count of lines containing word “ABC”.?

grep –c “ABC” file1

<< 1 2 3 4 5 >>

Subscribe to get more Posts :