assignment of subject unix shell programming tb

7
KUVEMPU UNIVERSITY :- ASSIGNMENT FOR B.Sc(IT)-4 th sem : SUBJECT: UNIX & SHELL PROGRAMMING SUBJECT CODE: BSIT-43 Assignment: TB (Compulsory) (1) What is a shell? Explain its importance. Ans- Shell is a separate, interactive program, for each user when he or she logs on. It acts as a interface between the user and the system. IMPORTANCE OF SHELL SCRIPT:- Shell acts as a command interpreter. It takes the commands and sets them for execution if possible, and returns a prompt to us when it is done and gets ready for our next command. (2) Write a UNIX command to count how many users have logged on to the UNIX system.

Upload: mukesh-kumar

Post on 29-Nov-2014

848 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Assignment of Subject Unix Shell Programming TB

KUVEMPU UNIVERSITY:-

ASSIGNMENT FOR B.Sc(IT)-4 th sem :

SUBJECT: UNIX & SHELL PROGRAMMINGSUBJECT CODE: BSIT-43

Assignment: TB (Compulsory)

(1) What is a shell? Explain its importance.

Ans- Shell is a separate, interactive program, for each user when he or she logs on. It acts as a interface between the user and the system. IMPORTANCE OF SHELL SCRIPT:-

Shell acts as a command interpreter. It takes the commands and sets them for execution if possible, and returns a prompt to us when it is done and gets ready for our next command.

(2) Write a UNIX command to count how many users have logged on to the UNIX system.Ans- The command to count the number of users logged on to the UNIX system is: Who || wc-l

(3) How is a job run periodically in UNIX system? Explain with an example.Ans- A job can be run periodically in UNIX system by a Unix utility called cron. The cron daemon takes care of running these background jobs, which are called cron jobs.

Crontab is a file which contains the schedule of cron entries to be run and at specified times. Cron checks the crontab at regular tables to see if there are any jobs scheduled.

Page 2: Assignment of Subject Unix Shell Programming TB

EXAMPLE- The following line in the crontab file removes all core files/user/user1 everyday at 7:30 PM. 30 19 * * * rm/user/user1/coreThe time schedule can be changed as follows to run the command at 5:30 PM on the 1st of Mar, June and September. 30 17 1 3,6,9 rm/user/user1/coreBy default cron jobs send an e-mail to the user account executing the cronjob. If this is not needed it puts the following command.

(4) What is a process? Explain the mechanism of process creation in UNIX system.

Ans- Process is basically an execution thread that can be used to execute in an address space which is constituted from data, text, and stack segment of a given program. A process always starts at the beginning of the given text segment and teminates at the occurrence of an exit command in the text. CREATION OF PROCESS:In Unix, only a process can create another process. Assuming that there is a process existing, it can create any number of processes, which are simply duplications of the former. The process that creates processes is called the parent process and the created processes are called children. Each child can in turn create more processes (i.e. grandchildren). This process of creation can continue until a required tree of process is achieved. In general, Unix allows a user process to create a hierarchy of processes. Process use the fork ( ) system call to create a new process.

(5) What is a filter? Explain any five filters in UNIX system.

Ans- A filter is a program that can take a flow of data from standard input, process it, and send the result on to standard output. Five filters of Unix are as follows:-

(a) grep filter- It searches a file for a particular pattern of characters and displays all lines that contain that pattern.

Page 3: Assignment of Subject Unix Shell Programming TB

Syntax- grep regular_ expression (filename) Regular expression is the pattern that is searched for.

(b) wc filter- It is used to count the number of lines, words, and characters in a disk file or in standard input. Syntax- wc [options] [filename/s].

(c) cut filter- It is useful when specific columns from the output of certain commands (such as ls-l, who) need to be extracted. It can also be used to extract specific columns from files. Syntax- cut [options] [filename/s].

(d) tr filter- It can be used to translate one set of characters to another. The tr filter translates the characters in the output only and does not effect the input file.

(e) cat- It displays the contents of a file and with its we can create a file also. We can create a file by using the command: Cat > filename.

Q6. what is shell script to check whether given year is a leap year or not?

Ans: echo “plz enter year”Read $a $b=`expr $a%4`If test $b = 0ThenEcho “leap year”ElseEcho “not a leap year”fi (7) Explain the different types of variables in shell.

Page 4: Assignment of Subject Unix Shell Programming TB

Ans- The different types of variables in shell are as under:-(a) Environment variables: Sometimes called special shell variables, or standard shell variables, they are used to tailor the operating environment to suit our needs. Examples include PATH, TERM, HOME, and MAIL.

(b) User-defined variables: These are variables that can be created by us.

(c) Positional Parameters: These are used by the shell to store the values of command-line arguments.

(8) What is the significance of write and talk command in UNIX?

Ans- Write and talk command are communication programs that allow users to talk to each other in a network. The write command copies lines from one users terminal to that of another user. The command is used by typing the following:- $ write username. Where, username is another logged in user. The recipient gets a message from the sender along with the sender’s username. If the recipient of the message writes back, communication will start between the two users and continues until an end-of-file is read from the terminal or an interrupt is sent. The talk command is used to have a visual communication program which copies line from a user’s terminal to that of another user. It allows text-based communication between two users. Example- If user1 wants to have a chat with user2 then user1 types the following:- $talk user2.

Page 5: Assignment of Subject Unix Shell Programming TB