Thursday, 8 March 2012

How can you check if your Linux machine on network has static or dynamically allocated IP? How can you change it from dynamic to static?

How can you check if your Linux machine on network has static or dynamically allocated IP? How can you change it from dynamic to static? Ans: Network configuration file can be looked at for checking if Linux machine has static or dynamically allocated IP. ifconfig can be used to check currently allocated IP. In Ubuntu the configuration file is /etc/network/interfaces. For dynamically allocated IP, it should state dhcp, e.g following entry: iface eth0 inet dhcp In order to change it to static IP allocation, dhcp should be changed to static and IP address, subnet mask, network address, broadcast address and gateway need to be mentioned. E.g. : iface eth0 inet static address 10.1.10.54 netmask 255.255.255.0 network 10.1.10.0 broadcast 10.1.10.255 gateway 10.1.10.1 Networking service needs to...

Clear Screen & Display Today date and Time In linux

Modify your shell, such that every time you enter clear, it clears screen and on top of new screen displays “Welcome username. You are using shel Today is date and time”. Where username is the name of the user logged in,shel is the path to the shell you are using and date and time is current date and time. 15 Marks In order to display “Welcome username. You are using shell. Today is date_and_time” following command can be used: echo Welcome $USER. You are using $SHELL. Today is $(date) In order to modify shell, such that every time clear is entered, this command is executed AFTER clearing the shell, an alias can be defined as follows: alias clear=”clear; echo Welcome $USER. You are using $SHELL. Today is $(date)...

What is difference between su and sudo? su be used instead of sudo for root privilege?

What is difference between su and sudo? How can su be used instead of sudo for getting access to root privilege? Ans: su is used for logging in as any other user, including root user. After entering user password, you can enter commands as that user unless u enter exit. In order to log in as root, just enter su and in order to enter as a different user enter suusername. su can be used for single command as: su user_name –c command sudo is used for gaining root privilege for a specific command. Adding sudo at the start of a command implies that root privilege is used for that command. In order to use sudo, the current user has to be added in sudoers file. sudo–i can be used for starting a shell as root user, but in that case password for the current user is required, not that of root. Thus,...

Write a (Perl or Bash) script which takes one or more filenames as arguments. If any of the files does not exist in the current directory display prompt. For each file, remove all the comments lines in the file.

Write a (Perl or Bash) script which takes one or more filenames as arguments. If any of the files does not exist in the current directory display prompt. For each file, remove all the comments lines in the file. #!/bin/bash if [ $# -eq 0 ] #If no file is given as argument then echo 'Please provide name of file as argument' #Display message else #If arguments are given for file #For each argument do if [ ! -f $file ] #If file does not exist then echo "File $file does not exist" #Display message else #If file exist echo "Original contents of file $file are:" #Display message cat $file #Display original file contents sed -e '/^#[^!]/d' $file > temp #sed used to remove lines which start with #, except those starting with #!. Result saved in file temp echo "File contents after removing comments...

Read file in linux, check if the group exists,Check if the user exists,Add the group if it does not exists

You have a file named users. Each line in the file contains two words (space separated): a username and a group name. Write a (Perl or Bash) script to: 25 Marksa. read one by one each line in the fileb. check if the group exists, add the group if it does not existsc. check if the user exists, check the user belongs to the same group, if not change thegroup. Add user to the group if user does not existsd. Set the password of the user same as the username.e. On each step, display appropriate prompts (e.g., user added, user already exists etc.) Script: #!/bin/bash while read user group #Reading user and group from the file do echo CHECKING FOR USER $user and GROUP $group #Display message before checking for each user or group tmp_u=$(grep -w ^$user /etc/passwd) #Check if user exists. tmp_g=$(grep...

Pages 381234 »
 
Free Host | lasik surgery new york