Thursday, 18 December 2014

Tar Files extraction Unix / Linux

Q: How can I extract  specific file from a tar ball ?

Tar or Tar ball is a single file  bundled with files &/ directories. First  we will discuss about general extraction of a files from tar ball.

Unpack or extract a tar file :

To unpack or extract a tar file, type:
tar -xvf myfile.tar
some times to save more space and bandwidth , we  need compress the tar balls using compression techniques like gzip or bzip2.

To unzip and extract  those tar files, type as below 
For  .tar.gz files 
tar -xzvf myfile.tar.gz

For .tar.bz2
tar -xjvf myfile.tar.bz2
Where,
-x : Extract a tar ball.
-v : Verbose output or show progress while extracting files.
-f : Specify an archive or a tarball filename.
-j : Decompress and extract the contents of the compressed archive created by bzip2 program (tar.bz2 extension).
-z : Decompress and extract the contents of the compressed archive created by gzip program (tar.gz extension).
Now here comes our main purpose ,  to extract a specific file  from a tar file.

Extract Specific file from a tar ball:

To extract a single file called myfile1.txt, enter:
tar -xvf file.tar myfile1.txt
tar -xzvf file.tar.gz myfile1.txt
tar -xjvf file.tar.bz2 myfile1.txt
You can also specify path such as home/um/myfile2.txt, enter:
tar -xvf file.tar home/um/myfile2.txt
tar -xzvf file.tar.gz home/um/myfile2.txt
tar -xjvf file.tar.bz2 home/um/myfile2.txt

How to Extract a Single Directory?

To extract a single directory called /home/um, enter:
tar -xvf file.tar home/um
tar -xzvf file.tar.gz home/um
tar -xjvf file.tar.bz2 home/um

Sample O/P:
home/um/
home/um/ddl/
home/um/ddl/default
home/um/ddl/bin/config.conf
home/um/ddl/daemon.conf
home/um/ddl/config/system.sh

Wednesday, 17 December 2014

MobaXterm free Xserver and SSH client

Recently when I am browsing internet  for Unix connectivity tools I came across a wonderful tool called MobaXterm. As per the MobaXterm team  its "an enhanced terminal for Windows with an X11 server, a tabbed SSH client and several other network tools for remote computing (VNC, RDP, telnet, rlogin). MobaXterm brings all the essential UNIX commands to Windows desktop, in a single portable exe file which works out of the box".

Downaload:There are two different versions available, one is free version and other is Pro.
I think free version is good enough to accommodate our daily tasks. If you still  feel you need  more then  go for Pro.

Download Link

The following are  the key features mentioned by them.

Key Features:
  • Free X server fully configured (based on Xorg)
  • Tabbed terminal based on PuTTY / MinTTY with antialiased fonts and macro support
  • Easy DISPLAY exportation from any remote host
  • X11-Forwarding capability in OpenSSH
  • Several Unix/Linux commands based on Cygwin (rsync, wget, sed, awk, grep, cd, ls, cat, cp, ...)
  • A session manager with all the network clients you need: RDP, VNC, SSH, telnet, rsh, FTP, SFTP and XDMCP
  • Program without installation that you can start from an USB stick
  • Light and portable application, packaged in a single executable


I am really enthralled by the features its offering.Here are few snippets.

1) Inbuilt Unix Command Support :
When you open MobaXterm  it will automatically  open session which supports many of Unix/Linux based commands  (ls, cd, grep, awk, tail, cut, sed, wget, rsync, telnet, ssh, rlogin, rsh etc ) based on Cygwin. You can further add packages using this link plugins.

2)Tabbed Sessions:
When ever you open a session , it will be open as tabbed session, just like Putty Connection Manager.
You can also save your session along with usernames and passwords

3)X11-Forwarding
The SSH connection configured with automatic X-11 forwarding.You can use this as fully configured "X server " and also supports OpenGL.

4) Automatic SFTP Support:
A SFTP session is automatically opened when you open a ssh session on leftside. You can  download or upload files directly with a drag and drop from/to the remote server.You  can also  edit And save the files with one click open it in MobiXeditor or  which ever the text editor on your system.

5) Remote Windows Connections using RDP: 
  You can access the remote windows machines using RDP adding as connection.

6) Split-mode Terminal:
you can display up to 4 terminals at the same time in the main window. It is very useful for monitoring 4 remote computers or for comparing outputs of 2 terminals.

7) Multiple Sessions Support:
It will support various session types like SSH,RSH,Telnet,Xdmcp,RDP,VNC, SFTP,FTP many more.

8) Muti Execution Mode:
There us a facility just klike PuttyCM, You can run one single command in all the open sessions.But be more cautious when you are using this facility, need to be careful on which sessions you are running this.

---
There are lot more features and further information you can refer the following link.
more features link

Saturday, 15 November 2014

Manually Installing PHP in Linux

Before installing php,  we need to install apache.The most recent version of Apache HTTP Server may be obtained from >> Apache Download.

1) Download  & Unpack Apache HTTP server Package:

Download and unpack Apache http server package  from the location listed above, and unpack it.
Download Link: Apache Download
gzip -d httpd-2_x_NN.tar.gz
tar -xf httpd-2_x_NN.tar

2) Download  & Unpack PHP source Package:

Download Link: PHP Dowanlod
gunzip php-NN.tar.gz
tar -xf php-NN.tar

3) Build and install Apache:

cd httpd-2_x_NN
./configure --enable-so
make
make install

4) Start  & Start Apache:

/usr/local/apache2/bin/apachectl start
stop the  apache to configure php
/usr/local/apache2/bin/apachectl stop

5) Configure & Build  PHP Package:

cd ../php-NN
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
make
make install

6)Setup your php.ini

cp php.ini-development /usr/local/lib/php.ini
You may edit your .ini file to set PHP options. If you prefer having php.ini in another location, use --with-config-file-path=/some/path in step 5.

If you instead choose php.ini-production, be certain to read the list of changes within, as they affect how PHP behaves.

7) Edit your httpd.conf to load the PHP module:

LoadModule php5_module modules/libphp5.so

8) Tell Apache to  parse PHP extensions:

If you instead choose php.ini-production, be certain to read the list of changes within, as they affect how PHP behaves.
let's have Apache parse .php files as PHP. Add to httpd.conf file.
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>
Or, if we wanted to allow .php, .php2, .php3, .php4, .php5, .php6, and .phtml files to be executed as PHP, but nothing else, we'd use this:
FilesMatch "\.ph(p[2-6]?|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
And to allow .phps files to be handled by the php source filter, and displayed as syntax-highlighted source code, use this:
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

9) Start Apache:

/usr/local/apache2/bin/apachectl start
OR
service httpd restart
That’s all.

Monday, 20 October 2014

WEBMIN- Managing Unix Systems Graphically

What is Webmin?

Webmin is a web-based interface for system administration for Unix. Using any modern web browser, you can setup user accounts, Apache, DNS, file sharing and much more.

Demo:

http://webmin-demo.virtualmin.com/   login: demo &  password: demo.

Download Link:

How to Install:

Install on RedHat/CentOS/Fedora:

If you are using the RPM version of Webmin, first download the file from the downloads page , or run the command :
[root@UMLinux1 ~]# wget http://prdownloads.sourceforge.net/webadmin/webmin-1.710-1.noarch.rpm

and then run the command

[root@UMLinux1 ~]# rpm -U webmin-1.710-1.noarch.rpm
The rest of the install will be done automatically to the directory /usr/libexec/webmin, the administration username set to root and the password to your current root password. You should now be able to login to Webmin at the URL http://localhost:10000/.Or if accessing it remotely, replace localhost with your system's IP address.

If you want to connect from a remote server and your system has a firewall installed, see this page for instructions on how to open up port 10000.

Install on Debian:

If you are using the DEB version of webmin, first download the file from the downloads page , or run the command :
[root@UMLinux1 ~]# wget http://prdownloads.sourceforge.net/webadmin/webmin_1.710_all.deb

then run the command :

[root@UMLinux1 ~]# dpkg --install webmin_1.710_all.deb
The install will be done automatically to /usr/share/webmin, the administration username set to root and the password to your current root password. You should now be able to login to Webmin at the URL http://localhost:10000/. Or if accessing it remotely, replace localhost with your system's IP address.

How to Stop& Start Webmin Services:

In order to start the Webmin service on CentOS (Linux) you will need to issue the following command:
[root@UMLinux1 ~]# service webmin start
You can check to make sure that Webmin is running by issuing the following command:
[root@UMLinux1 ~]# service webmin status
Webmin (pid 1729) is running
[root@UMLinux1 ~]#
If you wish to configure your server to ensure that the Webmin service is started at boot time you can issue the following command:
[root@UMLinux1 ~]# chkconfig --level 3 webmin on
To verify that Webmin will start at boot, issue the following command:
[root@UMLinux1 ~]# chkconfig --list webmin
webmin 0:off 1:off 2:off 3:on 4:off 5:off 6:off
[root@UMLinux1 ~]#
In the previous listing, Webmin is listed to start in run level 3, which is the default run level that the dedicated servers boot into.

Saturday, 11 October 2014

Run VIO commands from the HMC using "viosvrcmd" without VIOs Passwords

Recently  we got a situation where  in we don't know the passwords of  either padmin/root of VIOS  but need to run commands in VIOs.

Found an interesting command  in HMC  called "viosvrcmd",which will enble us to run commands on VIOs through HMC.
viosvrcmd -m managed-system {-p partition-name | --id partition-ID} -c "command" [--help]
Description: viosvrcmd issues an I/O server command line interface (ioscli) command to a virtual I/O server partition.

The ioscli commands are passed from the Hardware Management Console (HMC) to the virtual I/O server partition over an RMC session.

RMC does not allow interactive execution of ioscli commands.
-m    VIOs managed system name

-p    VIOs hostname

--id  The partion ID of the VIOs

Note:You must either use this option to specify the ID of the partition, or use the  -p option to specify the partition's name. The --id and the -p options are mutually exclusive.

-c    The I/O server command line interface (ioscli) command to issue to the virtual I/O      server partition.

Note: Command must be enclosed in double quotes. Also, command cannot contain the      semicolon (;), greater than (>), or vertical bar (|) characters.

--help  Display the help text for this command and exit.
Here is an example:
hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "ioslevel"
2.2.0.0
Since  we can't give the ; or > or |  in the command , if you need to process the output using filters , you can use that after "".
hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "lsdev -virtual" | grep vfchost0
vfchost0         Available   Virtual FC Server Adapter

What if  you want to run  command as root (oem_setup_env) ,  

got a method from internet
hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "oem_setup_env
> whoami"
root

You can  run in one shot like below

hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "oem_setup_env\n whoami"
root
If you need to run multiple commands , you can use them by assiging the commands to a variable and call the variable in place of the command parameter.
hscroot@umhmc:~>command=`printf  "oem_setup_env\nchsec -f /etc/security/lastlog -a unsuccessful_login_count=0 -s padmin"`

hscroot@umhmc:~>viosvrcmd -m umfrm570 -p umvio1 -c "$command"

Friday, 10 October 2014

Expressions used with if condition in shell scripts

1-1. Primary Expressions

PrimaryMeaning
[ -a FILE ]True if FILE exists.
[ -b FILE ]True if FILE exists and is a block-special file.
[ -c FILE ]True if FILE exists and is a character-special file.
[ -d FILE ]True if FILE exists and is a directory.
[ -e FILE ]True if FILE exists.
[ -f FILE ]True if FILE exists and is a regular file.
[ -g FILE ]True if FILE exists and its SGID bit is set.
[ -h FILE ]True if FILE exists and is a symbolic link.
[ -k FILE ]True if FILE exists and its sticky bit is set.
[ -p FILE ]True if FILE exists and is a named pipe (FIFO).
[ -r FILE ]True if FILE exists and is readable.
[ -s FILE ]True if FILE exists and has a size greater than zero.
[ -t FD ]True if file descriptor FD is open and refers to a terminal.
[ -u FILE ]True if FILE exists and its SUID (set user ID) bit is set.
[ -w FILE ]True if FILE exists and is writable.
[ -x FILE ]True if FILE exists and is executable.
[ -O FILE ]True if FILE exists and is owned by the effective user ID.
[ -G FILE ]True if FILE exists and is owned by the effective group ID.
[ -L FILE ]True if FILE exists and is a symbolic link.
[ -N FILE ]True if FILE exists and has been modified since it was last read.
[ -S FILE ]True if FILE exists and is a socket.
[ FILE1 -nt FILE2 ]True if FILE1 has been changed more recently than FILE2, or if FILE1 exists and FILE2 does not.
[ FILE1 -ot FILE2 ]True if FILE1 is older than FILE2, or is FILE2 exists and FILE1 does not.
[ FILE1 -ef FILE2 ]True if FILE1 and FILE2 refer to the same device and inode numbers.
[ -o OPTIONNAME ]True if shell option "OPTIONNAME" is enabled.
[ -z STRING ]True of the length if "STRING" is zero.
[ -n STRING ] or [ STRING ]True if the length of "STRING" is non-zero.
[ STRING1 == STRING2 ] True if the strings are equal. "=" may be used instead of "==" for strict POSIX compliance.
[ STRING1 != STRING2 ] True if the strings are not equal.
[ STRING1 < STRING2 ] True if "STRING1" sorts before "STRING2" lexicographically in the current locale.
[ STRING1 > STRING2 ] True if "STRING1" sorts after "STRING2" lexicographically in the current locale.
[ ARG1 OP ARG2 ]"OP" is one of -eq, -ne, -lt, -le, -gt or -ge. These arithmetic binary operators return true if "ARG1" is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to "ARG2", respectively. "ARG1" and "ARG2" are integers.

Expressions may be combined using the following operators, listed in decreasing order of precedence:

1-2. Combining expressions

OperationEffect
[ ! EXPR ]True if EXPR is false.
[ ( EXPR ) ]Returns the value of EXPR. This may be used to override the normal precedence of operators.
[ EXPR1 -a EXPR2 ]True if both EXPR1 and EXPR2 are true.
[ EXPR1 -o EXPR2 ]True if either EXPR1 or EXPR2 is true.
The [ (or test) built-in evaluates conditional expressions using a set of rules based on the number of arguments. Just like the if is closed with fi, the opening square bracket should be closed after the conditions have been listed.