Posts

Showing posts from 2014

Unix/Linux - Special Variables For Shell

There are many special variables reserved for Shell and can be useful while scripting , below is the detailed summary of some of those :- Variable Description $0 The filename of the current script. $n These variables correspond to the arguments with which a script was invoked. Here n is a positive decimal number corresponding to the position of an argument (the first argument is $1, the second argument is $2, and so on). $# The number of arguments supplied to a script. $* All the arguments are double quoted. If a script receives two arguments, $* is equivalent to $1 $2. $@ All the arguments are individually double quoted. If a script receives two arguments, $@ is equivalent to $1 $2. $? The exit status of the last command executed. $$ The process number of the current shell. For shell scripts, this is the process ID under which they are executing. $! The process number of the last background command. The command-line arguments $1, $2, $3,...$9 are positional parameters, ...

Prevent users from seeing processes that do not belong to them

hidepid option :- this can be done by hidepid option which have below values :- hidepid=0 -  anybody may read all world-readable /proc/PID/* files (default). hidepid=1 -  It means users may not access any /proc/ */ directories, but their own. hidepid=2  - It means hidepid=1 plus all /proc/PID/ will be invisible to other users. Type the following mount command: # mount -o remount,rw, hidepid=2 /proc To make above configuration across the reboot , edit /etc/fstab for the same : # vi /etc/fstab update proc entry with hidepid=2 as below proc    /proc    proc    defaults, hidepid=2     0     0 If you want yo give access to particular group to see all process (hidepid=0 mode), you need to use gid=<group_name> option: proc /proc proc defaults,hidepid=2, gid=admin 0 0 You can confirm this hidepid value after remount as below :- #mount | grep -i proc

Tar Command With Simple Example

tar command is the primary archiving utility for unix/linux. Today we will see uses of  "tar" with an example of tar a whole directory (old_dir) content to another directory(new_dir) 1.Create an archive $ ls old_dir  new_dir $ cd old_dir $ tar -cvf new_dir/backup.tar .    <<--here use period "." not "*" as "*" will not include hidden files/dir (specially if you are using tar for /home dir as lots of hidden files/dir will be there i.e. .ssh,.bashrc etc) In the above command: c – create a new archive v – verbosely list files which are processed. f – following is the archive file name 2.Extracting (untar) an archive $ cd new_dir $ ls backup.tar $ tar -xvf backup.tar x – extract files from archive

Clearing the udid_mismatch flag for non-clone disks

If the disk is not a cloned disk, this behavior could result in errors during disk group import, depending on the import flags. When a disk group is imported, VxVM may skip cloned disks. Also, the import may fail because a disk group has a combination of cloned and non-cloned disks. If the disk is not a cloned disk, you must manually clear the udid_mismatch flag on the disk before the disk group import can succeed. Note: In a cluster, perform all the steps on the same node. (i.e. freeze & offline service group etc. ) To clear the udid_mismatch flag from a disk Retrieve the refreshed list of disks showing the udid_mismatch flag or the clone_disk flag. Use one of the following methods: Run the following commands: # vxdisk scandisks # vxdisk list | egrep "udid_mismatch|clone_disk" Or, run the following command: # vxdisk -eoalldgs list | egrep "udid_mismatch|clone_disk" If the disks are part of an imported disk group, deport the dis...

Send an email using Telnet

Here are simple steps on how to send an email using telnet. This a great way to test your mail server configuration such as  sendmail or postfix without a need for a email client. First telnet to yor mail server: $ telnet mail.mymailserver.com 25 Use HELO command to tell mail server from which domain you are coming from: HELO UL_Daily_Dose.in Now we need to state from which address this email will be sent. This is done with MAIL FROM: command: MAIL FROM: AJM@UL_Daily_Dose.in Next step is to specify recipient with RCPT TO: RCPT TO: XYZ@remote_box.com Now we ca star writing some subject and body. To do that we need to use DATA command. First type DATA followed by Subject: and body. Once done enter . to send email to be queued. DATA Subject: Sending an email using telnet Hello, Here is my body? Do you like it? cheers . Do not forget "." at the end of the message. To quit type quit

How To Get Hardware Information On Linux Using dmidecode Command

dmidecode command reads the system DMI table to display hardware and BIOS information of the server. Apart from getting current configuration of the system, you can also get information about maximum supported configuration of the system using dmidecode. For example, dmidecode gives both the current RAM on the system and the maximum RAM supported by the system. Following are the different DMI types available.        Type   Information        ----------------------------------------           0   BIOS           1   System           2   Base Board           3   Chassis           4   Processor           5   Memory Controller           6   Memory Module           7   Cache       ...

SSH Login Without Password Using ssh-keygen & ssh-copy-id

Passwordless login ,yeah as name suggested its very much tempting and will give you a comfort zone. ssky-keygen and ssh-copy-id these two commands will make your life easy in that case, lets follow them as below :- ssh-keygen  creates the public and private keys.  ssh-copy-id  copies the local-host’s public key to the remote-host’s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys. Step 1: Make public and private keys using ssh-key-gen on local-host AJM@ local-server $ [Note: You are on local-host here] AJM@ local-server $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/AJM/.ssh/id_rsa):[Enter key] Enter passphrase (empty for no passphrase): [Press enter key] Enter same passphrase again: [Pess enter key] Your identification has been saved in /home/AJM/.ssh/id_rsa. Your public key has been saved in /home/AJM/.ssh/id_rsa...