Cs Assignment
Cs Assignment
2. Use the --version option to find out which version you are running.
Ans:
Command: bash --version
3. Which shell configuration files are read when you login to your system using the graphical
user interface and then opening a terminal window?
Command: sudo /bin/bash
4. Can you explain why bash does not exit when you type Ctrl+C on the command line?
Ans:
In Section 1.2.2.3.3 the Guide explains that an interactive shell catches and handles SIGINT.
This keeps Ctrl+C from exiting the shell. Using Ctrl+C is a common way of sending the SIGINT
signal to a running shell, script, or program. However, it is not required for whatever
receives the SIGINT to actually exit; it may do something else in response.
5. Write a script to determine how many processes are currently running on your system. Use
ps and wc, the first line of the output of ps is not a process!
Ans:
Create a script name process.sh with command sudo gedit process.sh with following
content:
Navigate to a directory where your process.sh is located and make the file executable:
Sudo chmod +x process.sh
Run the script by type ./process.sh then it will respond as below:
6. Write a script to display the system hostname. Only the name, nothing more!
Ans:
Create a script name hostname.sh with command sudo gedit hostname.sh with following
content:1
Navigate to a directory where your hostname.sh is located and make the file executable:
Sudo chmod +x hostname.sh
Run the script by type ./hostname.sh then it will respond as below:
7. Write a script to display the path to your homedirectory and the terminal type that you are
using. Additionally it shows all the sevices started up in runlevel 3 on your system. (hint: use
HOME, TERM and ls /etc/rc3.d/s*)
Ans:
Create a script name q7.sh with command sudo gedit q7.sh with following content:
Navigate to a directory where your q7.sh is located and make the file executable:
Sudo chmod +x q7.sh
Run the script by type ./q7.sh then it will respond as below:
8. Create 3 variables, VAR1, VAR2 and VAR3; initialize them to hold the values "thirteen", "13"
and "Happy Birthday" respectively.
i) Display the values of all three variables.
ii) Are these local or global variables?
iii) Remove VAR3.
iv) Can you see the two remaining variables in a new terminal window?
Ans:
(i),(iii)
(ii) If variables are exported, there are global variables. However, if these variables are not
export, there are local.
(iv) No, two remaining variables cannot be seen in new terminal window except new shell.
9. Edit /etc/profile so that all users are greeted upon login (test this).
i) For the root account, set the prompt to something like "Danger!! Root is doing stuff in \w",
preferably in a bright color such as red or pink or in reverse video mode.
ii) Make sure that newly created users also get a nice personalized prompt which informs
them on which system in which directory they are working. Test your changes by adding a
new user and logging in as that user.
Ans:
(i)
Add “setterm –reverse” and “echo DANGER THE ROOT IS WORKING $(pwd) at last line.
Navigate to a directory where your q10.sh is located and make the file executable:
Sudo chmod +x q10.sh
Run the script by type ./q10.sh then it will respond as below:
11. Write a script that will display localhost information from the /etc/hosts file, display the line
number(s) matching the search string and count the number of occurrences of the string.
Ans:
Create a script name q11.sh with command sudo gedit q11.sh with following content:
Navigate to a directory where your q11.sh is located and make the file executable:
Sudo chmod +x q11.sh
Run the script by type ./q11.sh then it will respond as below:
12. Write a script that will make a list of files in your home directory that were
changed less that 10 hours ago, using grep, but leave out directories. The
script should generate comprehensible output.
Ans:
Create a script name q12.sh with command sudo gedit q12.sh with following content:
Navigate to a directory where your q12.sh is located and make the file executable:
Sudo chmod +x q12.sh
Run the script by type ./q12.sh then it will respond as below: