Yearly Archives: 2017

How to restart Apache server in Linux

Learn how to restart Apache webserver in Linux from the command line. Know log file locations to look for troubleshooting during the restart process.

Apache webserver is one of the most widely used web servers for the Linux environment. Its easy webserver configuration, quick SSL configuration, separated log files make it easy to manage for sysadmin.

In this post, we will be seeing how to restart apache instances in Linux from the command line. We will also see its log files which can help us while troubleshooting the restart process.

Apache instance normally resides in /etc/httpd directory. If you have multiple instances running on the same machine then they might be in different directories under /etc/httpd/httpd-Name1, /etc/httpd/httpd-Name2 etc. It is recommended to have different user ids to run different instances so that they can be managed separately well.

Check running Apache:

Currently running Apache instance can be identified by using any of below commands :

root@kerneltalks # ps -ef |grep -i httpd
apache   15785 20667  0 07:50 ?        00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache   15786 20667  0 07:50 ?        00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache   15787 20667  0 07:50 ?        00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache   15788 20667  0 07:50 ?        00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache   15789 20667  0 07:50 ?        00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache   15790 20667  0 07:50 ?        00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start

Since my machine has multiple Apache instances running, you can see the same PPID for all processes. This will be PPID of main httpd service.

root@kerneltalks # service httpd status httpd (pid  20667) is running... 

To stop Apache :

To stop Apache we need to invoke Apache control script and provide it with the configuration file name (so that it knows which instance to stop in case of multiple instances).

# /usr/sbin/apachectl -f /etc/httpd/conf/httpd.conf -k stop

In the above example apachectl is supplied with conf file location (-f) and option (-k) to stop. Once above command is executed, you will notice httpd processes are no more visible in ps -ef output.

In case of single instance only you can directly stop service to stop Apache.

# service httpd stop

Once apache is stopped you will also notice that /var/httpd/logs/access.log also stops populating.

To start Apache:

To start it again you need to invoke apachectl with start argument.

# /usr/sbin/apachectl -f /etc/httpd/conf/httpd.conf -k start

In case of single instance you can directly start service.

# service httpd start

Once Apache is started backup you will see httpd processes in ps -ef output. Also access.log will start populating again.

If Apache is not starting up (after you made changes in configurations) then you need to check error.log file for reasons. It resides under /etc/httpd/logs directory.

To restart Apache :

Above both operations can be combined with restart options. When invoked, it will stop the instance first and then start it again.

# /usr/sbin/apachectl -f /etc/httpd/conf/httpd.conf -k restart

# service httpd restart

Above both commands restart Apache instances.

6 ways to manage service startups using chkconfig in Linux

Learn chkconfig command to list, turn on, or turn off system services during different run levels. Also, see how to control xinetd managed system service.

The chkconfig utility in Linux is a command-line tool to manage system services startups in run levels starting from 0 to 6. Run levels are different system stages in which the system can run with different numbers and combinations of services available for its users. There are mainly 7 run levels defined in the kernel world whereas 0,1 and 6 are not relative in this post. 0,6 run levels are boot/shut related whereas 1 is the single-user mode and we are seeing service management here which is normally comes in a picture for multi-user mode. So only 2,3,4,5 are the run levels that are covered by chkconfig utility when you are altering any services.

chkconfig controls which system service starts in which run level. It can even completely shuts off service so that it won’t run at any run level too. There are xinetd controlled system services that can be turned on or off irrespective of run level. These can be managed through chkconfig too.

Chkconfig is capable of below tasks:

  1. Overview of list of services and their run-level wise availability
  2. Details of individual system service
  3. Enable service at certain/all run levels
  4. Disable service
  5. Enable xinetd managed service
  6. Disable xinetd managed service

If you are on the Ubuntu server then probably chkconfig won’t work on Ubuntu. You can alternatively use update-rc.d command there.

We will see each of the above options in detail with related options and examples.

1. Overview of services and their run-level availability :

For this task, chkconfig displays a list of system services. Against every service, it displays all run levels 0 to 6 and on/off parameter. On means, service is enabled at that run level, and off means service is disabled at that run level. To view this you can run chkconfig command without any argument or with --list option.

# chkconfig --list
NetworkManager  0:off   1:off   2:off   3:off   4:off   5:off   6:off
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrtd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off
atd             0:off   1:off   2:off   3:on    4:on    5:on    6:off
auditd          0:off   1:off   2:on    3:on    4:on    5:off   6:off
autofs          0:off   1:off   2:off   3:on    4:on    5:on    6:off

-----output clipped-----
xinetd based services:
        chargen-dgram:  off
        chargen-stream: off
        time-stream:    off
----- output clipped -----

In the above output for example system service autofs is enabled for run level 3,4,5 and disabled for 0,1,2,6. It also shows xinetd based service status at the bottom. These services only have on or off status (no run level based status)

2. Details of individual service

In this task the same output as above can be obtained only for a particular service. It is as good as grepping out that service line from the above output. This task can be accomplished by using the service name as an argument to --list option.

# chkconfig --list nfs
nfs             0:off   1:off   2:off   3:off   4:off   5:off   6:off

# chkconfig --list rsync
rsync           off

3. Enable service at certain/all run levels :

Let’s see how to enable service for a particular/all run level. For this task, you need to specify levels (--level) on which services need to enable, followed by service name and lastly on a state.

# chkconfig --level 34 autofs on

In above example we are enabling autofs service in run level 3 and 4.

To enable it in all run levels i.e. 2,3,4,5 you can skip --level option.

# chkconfig autofs on

The above example enables autofs system service at all run levels. You can verify if the service state is set properly as specified in the command, by viewing chkconfig --list output.

4. Disable service

To disable service at certain/all run levels, sane above command can be used only ‘off’ state needs to be specified at the end instead of ‘on’ state.

# chkconfig --level 34 autofs off <<turns off at run level 3 & 4

# chkconfig autofs off <<turns off on all run levels

Make a note that this change is not immediate. Enabling or disabling services will change settings but takes effect only when the system will enter a specific run level after the execution of the command.

5. Enable xinetd managed service:

Since xinetd managed services cant be tagged to run-levels, you can not specify --level option with commands associated with them. To enable xinetd managed service, you need to mention the service name followed by ‘on’ state.

# chkconfig rsync on

Make a note that, change in xinetd managed services will be instant after the execution of the command.

6. Disable xinetd managed service:

To disable xinetd managed services opt ‘off’ state in above command.

# chkconfig rsync off




Observe state change in chkconfig --list output.

How to create tar file in Linux or Unix

Learn how to create tar file in Linux or Unix operating system. Understand how to create, list, extract tar files with preserving file permissions.

TAR is a short form of tape archive. They are used to sequentially read or write data. Compiling a huge file list or deep directory structure into a single file (tar file) is what we are seeing in this post. This resulting single file sometimes termed as tarball as well.

Creating tape archives of files or directories is extremely important when you are planning to FTP a huge pile of them to another server. Since each file opens a new FTP session and closes it after transfer finishes, if the number of files is huge then FTP takes forever to complete data transfer (even if size of each file is small). Even if you have an ample amount of bandwidth, due to session open and close operations FTP slows down to knees. In such cases, archiving all files in single tarball makes sense. This single archive can transfer at maximum speed and making transfer quickly. After transfer, you can again expand the archive and get all files in place the same as the source.

Normally its good practice to first zip files or directories and then create a tape archive of it. Zipping reduces their size and tar packs these reduced size files in single tarball! In Linux or Unix, command tar is used to create a tar file. Let’s see different operations that can be handled by tar command.

How to create tar file :

To create tar file -c option is used with tar command. It should be followed with the filename of the archive, normally it should have *.tar extension. It for users to identify its a tar archive, because Linux/Unix really don’t care about an extension.

# tar -cvf file.tar file2 file3
file2
file3
# ll
total 32
-rw-r--r-- 1 root users    40 Jan  3 00:46 file2
-rw-r--r-- 1 root users   114 Jan  3 00:46 file3
-rw-r--r-- 1 root users 10240 Jan  9 10:22 file.tar

In the above output, we have used -v (verbose mode) for -c option. file.tar is archive name specified and the end of the command is stuffed with a list of files to be added in the archive. The output shows filename on the terminal which is currently being added to the archive. Once all files are processed, you can see the new archive in the specified path.

To add directories in the tar file, you need to add directory path at end of the same command above.

# tar -cvf dir.tar dir4/
dir4/
dir4/file.tar
dir4/file1
dir4/file3
dir4/file2

If you use a full absolute path in command then tar will remove leading / so making members path relative. When archive will be deflated then all members will have a path starting with the current working directory/specified directory rather than leading /

# tar -cvf dir2.tar /tmp/dir4
tar: Removing leading `/' from member names
/tmp/dir4/
/tmp/dir4/file.tar
/tmp/dir4/file1
/tmp/dir4/file3
/tmp/dir4/file2

You can see / being removed warning in output above.

How to view content of tar file :

Tar file content can be viewed without deflating it. -t i.e. table option does this task. It shows file permissions, ownerships, size, date timestamp, and relative file path.

# tar -tvf dir4.tar
drwxr-xr-x root/users      0 2017-01-09 10:28 tmp/dir4/
-rw-r--r-- root/users  10240 2017-01-09 10:22 tmp/dir4/file.tar
-rw-r--r-- root/users  10240 2017-01-09 10:21 tmp/dir4/file1
-rw-r--r-- root/users    114 2017-01-03 00:46 tmp/dir4/file3
-rw-r--r-- root/users     40 2017-01-03 00:46 tmp/dir4/file2

In the above output, you can see the mentioned parameters in the same sequence displayed. Relative file path means when this tar file extracts it will create files of directories in PWD or path specified in the command line. For example in the above output, if you extract this file in /home/user4/data directory then it will create tmp directory under /home/user4/data and extracts all files in it i.e. under /home/user4/data/tmp.

How to extract tar file :

-x option extracts files from the tar file. As explained above, it will extract files and directories within tar into a relative path.

# tar -xvf dir4.tar
tmp/dir4/
tmp/dir4/file.tar
tmp/dir4/file1
tmp/dir4/file3
tmp/dir4/file2
# ll
total 36
-rw-r--r-- 1 root users 30720 Jan  9 10:28 dir4.tar
drwxr-xr-x 3 root users  4096 Jan  9 10:46 tmp
# ll tmp
total 4
drwxr-xr-x 2 root users 4096 Jan  9 10:28 dir4
# ll tmp/dir4
total 32
-rw-r--r-- 1 root users 10240 Jan  9 10:21 file1
-rw-r--r-- 1 root users    40 Jan  3 00:46 file2
-rw-r--r-- 1 root users   114 Jan  3 00:46 file3
-rw-r--r-- 1 root users 10240 Jan  9 10:22 file.tar

In the above outputs, step by step you can see tmp and dir4 structure created by tar command and extracted all files within it.

There are also few more options supported by tar-like appending files in the existing archives, zipping, updating new files in the existing archives, etc. We will see them in another post later. Leave us comments if you have any queries or suggestions.

How to resolve 83h/80h error in HPUX

Procedure to resolve Evpd inquiry page 83h/80h error in HPUX. This is LUN related error which may cause non-availability of device.

This post is about 83h/80h error which most of the times seen on HPUX servers. This error is caused by LUNs which are made visible to the server in a place where previously some LUNs were visible.

Normally, when you present a new LUN to HPUX server, after running ioscan -fnCdisk and insf -e commands they should be visible. But in some cases even after running these commands, you don’t see LUNs on the server. Obviously, as a troubleshooting step, you will check syslogs. And you will find below entry :

# tail /var/adm/syslog/syslog.log
May 3 16:46:05 destination vmunix: Evpd inquiry page 83h/80h failed or the current page 83h/80h data do not match the previous known page 83h/80h data on LUN id 0x0 probed beneath the target path (class = tgtpath, instance = 23) The lun path is

This entry denotes that a new device is made visible on the path which was in use by some other device in the past. To avoid any mishap, the kernel is not accepting this new device by default. Here, you need to manually tell the kernel that this change is accepted and should be taken up into operation.

This can be done with replace_wwid command as suggested in error itself. Command will be :

# scsimgr -v -f replace_wwid -C lunpath -I 69
Binding of LUN path 4/0/5/1/0/4/0.0x5006048452aa4347.0x4034000000000000 with new LUN validated successfully

Note that, here id 69 is used from the error we saw in Syslog. Error log suggests that id 23 is passed known instance and id 69 is a new one. You have to use a new instance id in command.

Once LUN is validated successfully, you will be able to see it on the system after running ioscan and insf commands again!

Building different types of software depots in HPUX

Learn to build directory and tape software depots in HPUX. Package software or patch bundles according to the environment need to facilitate installation.

HPUX patch management is an important aspect of HPUX server administration which includes downloads, distribution for installation, and final patch installation. In this post, we will be concentrating on the patch distribution part. HPUX patches can be in two forms: directory depots and tape depots (i.e. single *.depot file)

Directory depots are those which you normally get by expanding downloaded files from the HP software portal. This is good for local and network installs. Network installs can be done using: swinstall -s hostname:/some/place/directorydepotBut they are not useful for movement. If you want to move these software depots from one location to another with FTP then it’s a bit slow since there are plenty of files to copy.

Tape depots  (i.e. single *.depot file) is just like single RPM packages in the case of Linux. These are easy to copy, move, FTP. But these depots can’t be used for network installs as we saw earlier.

In this post, we will see how to create a tape depot using a directory depot and vice versa.

Create directory depot from tape depot:

You need to use swcopy command to transfer files in tape depot to directory depot. The command should be supplied with -s as source depot and turn off checking dependencies while copying using -x option.

# /usr/sbin/swcopy -x enforce_dependencies=false -s /tmp/PACPTHP_00001.depot \* @ /tmp/depot

=======  01/07/17 02:58:58 EDT  BEGIN swcopy SESSION (non-interactive)
         (jobid=testsrv2-0397)

       * Session started for user "root@testsrv2".

       * Beginning Selection
       * "testsrv2:/tmp/depot":  This target does not exist and
         will be created.
       * Source:                 /tmp/PACPTHP_00001.depot
       * Targets:                testsrv2:/tmp/depot
       * Software selections:
             HPOvLcore.HPOVBBC,r=6.00.000,a=HP-UX_B.11.00_32/64,v=HP,fr=6.10.050,fa=HP-UX_B.11.00_32/64
             HPOvLcore.HPOVCTRL,r=6.00.000,a=HP-UX_B.11.00_32/64,v=HP,fr=6.00.060,fa=HP-UX_B.11.00_32/64
             HPOvLcore.HPOVSECCO,r=6.00.000,a=HP-UX_B.11.00_32/64,v=HP,fr=6.00.040,fa=HP-UX_B.11.00_32/64
             HPOvLcore.HPOVXPL,r=6.00.000,a=HP-UX_B.11.00_32/64,v=HP,fr=6.00.070,fa=HP-UX_B.11.00_32/64
             HPOvLcore.HPOVBBC,r=6.00.000,a=HP-UX_B.11.22_IA,v=HP,fr=6.10.050,fa=HP-UX_B.11.22_IA
             HPOvLcore.HPOVCTRL,r=6.00.000,a=HP-UX_B.11.22_IA,v=HP,fr=6.00.060,fa=HP-UX_B.11.22_IA
             HPOvLcore.HPOVSECCO,r=6.00.000,a=HP-UX_B.11.22_IA,v=HP,fr=6.00.040,fa=HP-UX_B.11.22_IA
             HPOvLcore.HPOVXPL,r=6.00.000,a=HP-UX_B.11.22_IA,v=HP,fr=6.00.070,fa=HP-UX_B.11.22_IA
             HPOvPerf.HPOVPACC,r=4.70.000,a=HP-UX_B.11.00_32/64,v=HP,fr=10.50.060,fa=HP-UX_B.11.00_32/64
             HPOvPerf.HPOVPCO,r=4.70.000,a=HP-UX_B.11.00_32/64,v=HP,fr=10.50.060,fa=HP-UX_B.11.00_32/64
             HPOvPerf.HPOVPACC,r=4.70.000,a=HP-UX_B.11.22_IA,v=HP,fr=10.50.060,fa=HP-UX_B.11.22_IA
             HPOvPerf.HPOVPCO,r=4.70.000,a=HP-UX_B.11.22_IA,v=HP,fr=10.50.060,fa=HP-UX_B.11.22_IA
       * Selection succeeded.


       * Beginning Analysis and Execution
       * Session selections have been saved in the file
         "/home/sladmin/.sw/sessions/swcopy.last".
       * The analysis phase succeeded for "testsrv2:/tmp/depot".
       * The execution phase succeeded for "testsrv2:/tmp/depot".
       * Analysis and Execution succeeded.


NOTE:    More information may be found in the agent logfile using the
         command "swjob -a log testsrv2-0397 @
         testsrv2:/tmp/depot".

=======  01/07/17 02:59:02 EDT  END swcopy SESSION (non-interactive)
         (jobid=testsrv2-0397)

NOTE: you must escape or quote the asterisk (as above) because you don’t want the shell to replace it with a list of file names.

# ll /tmp/depot
total 32
dr-x------   6 root       sys             96 Jan  7 02:59 HPOvLcore
dr-x------   6 root       sys             96 Jan  7 02:59 HPOvLcore.2
dr-x------   4 root       sys             96 Jan  7 02:59 HPOvPerf
dr-x------   4 root       sys             96 Jan  7 02:59 HPOvPerf.2
dr-x------   7 root       sys           8192 Jan  7 02:59 catalog
-rw-r--r--   1 root       sys           1999 Jan  7 02:59 swagent.log

Resulting directory depot is ready to install locally (swinstall -s /tmp/depot) or over network (swinstall -s testsrv2:/tmp/depot)!

Create tape depot from directory depot:

Here swpackage command does the work of packaging all directory depot files into one single software depot file. Same command options as described above works here. Along with them, you need to specify media type as tape so that a single depot file will be generated.

# /usr/sbin/swpackage -x media_type=tape -s /tmp/depot \* @ /tmp/output.depot

=======  01/07/17 03:03:10 EDT  BEGIN swpackage SESSION

       * Session started for user "root@testsrv2".

       * Source:        testsrv2:/tmp/depot
       * Target:        testsrv2:/tmp/output.depot
       * Software selections:
             *


       * Beginning Selection Phase.
       * Reading the source depot "/tmp/depot".
       * Reading the contained files information for each selected
         product.

NOTE:    The temporary target depot "/var/tmp/pkgAAA005349" has been
         created.
       * Selection Phase succeeded.


       * Beginning Analysis Phase.
       * Analysis Phase succeeded.


       * Beginning Package Phase.
       * Packaging the product "HPOvLcore".
       * Packaging the fileset "HPOvLcore.HPOVBBC".
       * Packaging the fileset "HPOvLcore.HPOVCTRL".
       * Packaging the fileset "HPOvLcore.HPOVSECCO".
       * Packaging the fileset "HPOvLcore.HPOVXPL".

       * Packaging the product "HPOvLcore".
       * Packaging the fileset "HPOvLcore.HPOVBBC".
       * Packaging the fileset "HPOvLcore.HPOVCTRL".
       * Packaging the fileset "HPOvLcore.HPOVSECCO".
       * Packaging the fileset "HPOvLcore.HPOVXPL".

       * Packaging the product "HPOvPerf".
       * Packaging the fileset "HPOvPerf.HPOVPACC".
       * Packaging the fileset "HPOvPerf.HPOVPCO".

       * Packaging the product "HPOvPerf".
       * Packaging the fileset "HPOvPerf.HPOVPACC".
       * Packaging the fileset "HPOvPerf.HPOVPCO".
       * Package Phase succeeded.


       * Beginning Tapemaker Phase.
       * Copying the temporary depot to the tape
         "/tmp/output.depot".
       * Calculating the tape blocks required to copy the temporary
         depot to the tape "/tmp/output.depot".
NOTE:    The temporary depot requires 40540 Kbytes on the tape
         "/tmp/output.depot".
       * Writing the tape "/tmp/output.depot" (tape 1 of 1).
       * Writing the fileset "HPOvLcore.HPOVXPL" (1 of 12)
       * Writing the fileset "HPOvLcore.HPOVSECCO" (2 of 12)
       * Writing the fileset "HPOvLcore.HPOVBBC" (3 of 12)
       * Writing the fileset "HPOvLcore.HPOVCTRL" (4 of 12)
       * Writing the fileset "HPOvLcore.HPOVXPL" (5 of 12)
       * Writing the fileset "HPOvLcore.HPOVSECCO" (6 of 12)
       * Writing the fileset "HPOvLcore.HPOVBBC" (7 of 12)
       * Writing the fileset "HPOvLcore.HPOVCTRL" (8 of 12)
       * Writing the fileset "HPOvPerf.HPOVPACC" (9 of 12)
       * Writing the fileset "HPOvPerf.HPOVPCO" (10 of 12)
       * Writing the fileset "HPOvPerf.HPOVPACC" (11 of 12)
       * Writing the fileset "HPOvPerf.HPOVPCO" (12 of 12)
       * Tape #1: CRC-32 checksum & size: 684796198 41512960

       * Removing the temporary depot.
       * Tapemaker Phase succeeded.


=======  01/07/17 03:03:12 EDT  END swpackage SESSION

The .depot files are actually images of swinstall tapes, hence media_type=tape. Resulting .depot files can be used with swinstall for installation (swinstall -s /tmp/output.depot).

Merging multiple depots to create single depot:

Even multiple depots can be copied to single one using swcopy command.

# swcopy -x enforce_dependencies=false -s /some/where/thing1.depot \* @ /some/place/directorydepot
# swcopy -x enforce_dependencies=false -s /some/where/thing2.depot \* @ /some/place/directorydepot
# swcopy -x enforce_dependencies=false -s /some/where/thing3.depot \* @ /some/place/directorydepot

In the above example, we copied 3 tape software depots into the same directory depot. Now, this final directory depot contains all 3 tape depots patches/software ready to install. You can even create a single tape depot of this resulting directory depot using swpackage command. So you will have one tape depot which is having all 3 software depots inside!

Restore network Ignite backup on HPUX server

Learn how to restore network ignite backup on the HPUX server. Learn how to restore some other server’s OS backup on diff server provided hardware model is same

Ignite backup is an OS backup for HPUX OS. Ignite-Ux is a licensed tool developed by HP for its proprietary OS HPUX. Ignite backup can be taken on local tape or over the network on the Ignite server. In this post, we will be seeing how to restore network ignite backup on HPUX.

Pre-requisite :

Login to Ignite server and confirm below points :

  • Ignite backup of server is available under /var/opt/ignite/clients/<MAC of machine> directory
  • Directory ownership is bin:bin
  • Directory permissions are 755
  • One spare IP with same subnet of Ignite server for installation

Restoration :

Power up your server on which network ignite backup needs to restore. Halt boot process at EFI shell. Enter EFI shell to build your boot profile. Boot profile is profile which has booting options like boot path, network path, setting up boot network parameters for current server etc.

On EFI prompt, you need to execute below command to build your boot profile :

EFI> dbprofile -dn testprofile -sip x.x.x.x -cip x.x.x.x -gip x.x.x.x -m 255.255.255.0 -b "/opt/ignite/boot/nbp.efi"

in which,

  • -sip is Ignite server IP on which backup resides
  • -cip is machine IP to be used to boot machine with (spare IP I mentioned earlier)
  • -gip is gateway IP
  • -m is subnet mask
  • -b is boot path
  • -dn is profile name

Here we are building a profile with a name testprofile and related network parameters using which machine will boot and look for backup.

Now, boot your machine over LAN with this profile using below command from EFI shell:

EFI> lanboot select -dn testprofile

This will boot machine with taking himself IP defined in cip, with a gateway in gip, and will search for boot path on Ignite server sip. Once its query reaches the ignite server, it checks the MAC address from which query is generated and then serves backup boot path from the directory with that MAC address title. That’s why we checked permission and ownership previously.

Once everything goes smoothly, you will be served with a text-based GUI installation menu on your putty terminal. You can go ahead with the installation and restore network ignite backup.

Restoring serverA backup on serverB :

In the above method, it’s mandatory to have a backup of the same machine in place at the Ignite server to restore. In case you do not have backup and wish to restore another server’s backup then it can be done. The only thing is both machine’s hardware model should be the same.

For example, if you have serverA backed up on the Ignite server and want to restore this backup on serverB then it’s possible with a bit of trick provided serverA, and serverB should have the same hardware model.

For such instance, you need to copy an existing backup directory to the new one. The new directory should be named with the MAC address of serverB. MAC address of the new server can be obtained using lanaddress command in EFI shell in case it’s not installed with OS. After copying makes sure ownership and permissions are intact.

Once copy is done , you can follow above process and get the restore done!

How to zip, unzip files and directories in Linux / Unix

Learn how to zip, unzip files and directories in Linux or Unix. Compressing files helps in log management and makes data transfer easy.

Zipping files or directories compress data within them using  Lempel-Ziv coding (LZ77). This reduces the size of the resulting file. Lower size means lower storage requirement (log management) and faster transfer (FTP).

In Linux or Unix platforms gzip is widely available utility mostly native to OS which is used to zip, unzip files. In this post, we will see how to zip and unzip files using gzip utility with examples.

Compressing files

Zipping files i.e compressing is achieved by gzip without any option. You need to submit filename.xyz to gzip command. It will compress the file and the resulting file will have a name as filename.xyz.gz Point here to note is gzip removes the original file and keep new gz file in place.

# ll
total 12
-rw-r--r-- 1 root users  40 Jan  3 00:46 file2

# gzip file2

# ll
total 12
-rw-r--r-- 1 root users  63 Jan  3 00:46 file2.gz

Note in the above output after zipping original file file2 is vanished from the system and compressed archive file2.gz came in existence.

This command support wildcards like * or ? too. Also, you can supply a list of files to it and it will compress all the files supplied in the argument.

# gzip file2 file3

# ll
total 12
-rw-r--r-- 1 root users 63 Jan  3 00:46 file2.gz
-rw-r--r-- 1 root users 134 Jan  3 00:46 file3.gz

You can use forceful operation with -f option. This is helpful in case files to be compressed has multiple links in existence.

gzip also supports -v option i.e. verbose mode which shows all details about the operation being done.

# gzip -v *
file1:   45.7% -- replaced with file1.gz
file2:   22.5% -- replaced with file2.gz
file3:   10.5% -- replaced with file3.gz

In the above example, we zipped all files (hence *) within a directory using wild cards. Here verbose mode printed compression ratio for each file along with which file it replaced after the operation.

Compressing directories

Like files, even directories can be compressed recursively. When -r option is used, gzip command read through the given directory to its subtree structure and zips all the files it founds within.

# ll /tmp/dir3
total 12
-rw-r--r-- 1 root users  35 Jan  3 00:46 file1
-rw-r--r-- 1 root users  40 Jan  3 00:46 file2
-rw-r--r-- 1 root users 114 Jan  3 00:46 file3

# gzip -r /tmp/dir3

# ll /tmp/dir3
total 12
-rw-r--r-- 1 root users  51 Jan  3 00:46 file1.gz
-rw-r--r-- 1 root users  63 Jan  3 00:46 file2.gz
-rw-r--r-- 1 root users 134 Jan  3 00:46 file3.gz

In the above output, it recursively zipped all files within a given directory. This is a helpful option where there are hundreds of files in the directory.

Checking compressed files

To test the compressed archive you can use -t option with gunzip. If there are any issues with the compressed files it will report or else it will return you shell prompt.

# gzip -t file2.gz

You can even view compression details of this file using -l option with gunzip command. It shows, uncompressed and compressed size, compression ratio (0% if not known) and name of uncompressed file i.e. filename before compression

# gzip -l file2.gz
         compressed        uncompressed  ratio uncompressed_name
                 63                  40  22.5% file2

Un-Compressing files

To gain the original file from a compressed archive, -d option needs to be used and gz file to be supplied in the argument. It works vice versa and removes gz file and keeps the original file in the directory here. Recursive -r option works with -d too.

# gzip -d file2.gz

# ll
total 12
-rw-r--r-- 1 root users  40 Jan  3 00:46 file2

You can see file2 is back available now and the gz file has been removed. Using verbose mode prints more information about operations being done.

# gzip -v -d *
file1.gz:        45.7% -- replaced with file1
file2.gz:        22.5% -- replaced with file2
file3.gz:        10.5% -- replaced with file3

In the above output, we de-compressed three files in the same directory using wildcard *. It shows the compression ratio with which file replaced which file after decompression.

How to change your shell prompt to fancy one instantly

Learn to change shell prompt with your chosen character or value. Different values or shell variables can be defined to be shown as shell prompt.

After the user logged in to the system through Putty or command line he is greeted with blinking cursor in front of something called “Shell prompt”! Generally, the shell prompt with # denotes superuser and with $ denotes normal user. But going beyond these mainstream prompts, most of the admins choose the custom prompt for them and their users.

The most famous prompt used is showing the present working directory in prompt. So that users know in which directory he is while executing any command. Another widely used prompt is showing hostname. This ensures the user that he is working on the right terminal when many terminal windows are open. In this post, we will see how to set these prompts and some fancy prompts too.

Where to define Shell prompt :

Shell prompt is defined by PS1 variable in the profile file. This profile file can be any profile that is executed on user login. If multiple profiles have multiple values defined for PS1 then the last profile executed will decide the final value for PS1. For example when user logs in below profile execution can be followed :

/etc/profile -> ~/.bash_profile -> ~/.bashrc -> /etc/bashrc

In above flow system-wide profile i.e. /etc/profile calls bash profile which resides in the user’s home directory. This local profile calls bashrc script residing in the home directory. This bashrc calls up system-wide /etc/bashrc script to set the environment. In this case, PS1 value defined in /etc/bashrc would be the final one.

Sometimes there were no scripts called from profile then user’s home directory profile would be last resort to define PS1. If the profile file is missing in the user’s home directory the PS1 defined in /etc/profile will decide how your prompt looks.

How to define shell prompt :

Now, you know the file where prompt can be defined. Let’s see how to define it. It can be defined in a very basic way as below :

PS1=":->"
export $PS1

Here we are defining prompt as the symbol :-> The export command is not necessary but it’s good to have it in some flavors of Linux or Unix. Even you can test it by running command PS1=":->" on your terminal and you can see immediately your prompt will be changed to :->

You can even use an if-else loop in the profile file to decide which prompt should be served for particular users or terminal types.

Different useful prompts :

Below is the useful list of variables can be used in prompts :

Code
Description
PS1=”[$USER@$HOSTNAME]$” Shows prompt as [username@hostname]$
PS1=”[$USER@$HOSTNAME $PWD]$” Shows prompt as [username@hostname Present_directory]$
PS1=”[$HOSTNAME $PWD]$” Shows prompt as [hostname present_directory]$
PS1=”$HOSTNAME >” Shows prompt as hostname >

You can choose your own variations. See above-listed prompts in action below :

$PS1="[$USER@$HOSTNAME]$"
[user4@testsrv2]$

$PS1="[$USER@$HOSTNAME $PWD]$"
[user4@testsrv2 /home/user4]$

$PS1="[$HOSTNAME $PWD]$"
[testsrv2 /home/user4]$

$PS1="$HOSTNAME >"
testsrv2 >

Observe the first prompt is just $ sign. After each PS1 value change, prompt changes accordingly.

Some fancy prompts :

Here are some fancy prompts for fun!

$PS1=">-->"
>-->

$PS1="-=(^_^)=-:"
-=(^_^)=-:

$PS1="\m/ (-_-) \m/ :"
\m/ (-_-) \m/ :

$PS1="$USER rules $HOSTNAME >"
user4 rules testsrv2>

Hope you liked the post. Drop us your feedback, suggestions in comments below! Do follow us on Facebook, Twitter & Google+

Step by step procedure to take ignite tape backup in HPUX

A stepwise how-to guide for Ignite tape backup. Includes media check commands, backup log analysis, and troubleshooting steps.

Ignite is an OS backup solution for HPUX. This tool is developed by HP and available under the brand name Ignite-UX. It’s used to take system backup like a ghost image in the case of Windows. Complete OS can be restored using an ignite backup solution in case of any system failure. Ignite offers a network backup solution and tape backup solution. During network backup, OS backup is stored on ignite server over the network, and in event of restoring it’s restored over the network only (System should be booted with PXE boot). In tape backup, OS backed up in locally connected tape drive and restoration happens by booting system through bootable tape.

One needs to install this utility since it’s not native to HPUX. You can check if it’s installed or not using below command :

# /usr/sbin/swlist -l product |grep -i ignite
  Ignite-UX             C.7.12.519     HP-UX System Installation Services

If not installed, you need to purchase it and install on your HPUX machine.

In this post we will see how to take ignite tape backup along with its logs, troubleshooting and media check commands.

Media check :

Before starting your backup on tape you need to check if tape drive and media are functioning properly. After connecting your tape drive to the system and powering it on, you can identify it using ioscan -fnCtape & insf -e command. Its device name should be something like /dev/rmt/0mn . Once you identify device name for the tape you can check its status wit mt command:

# mt -t /dev/rmt/0mn status
Drive:  HP Ultrium 2-SCSI
Format:
Status: [41114200] BOT online compression immediate-report-mode
File:   0
Block:  0

Once you are able to get the status of media means tape drive is functioning properly and correctly identified in the kernel. Now you can go ahead with the backup procedure.

Taking ignite tape backup :

Ignite tape backup can be run using the command make_tape_recovery. This binary resides in /opt/ignite/bin. This command supports a list of options but we are seeing here most used ones :

  • -A: Checks disks/volume group and adds files in backup which are specified for backup inclusion
  • -v: Verbose mode
  • -I: Cause the system recovery process to be interactive when booting from the tape.
  • -x : Extra options (include=file|dir, exclude=file|dir,  inc_entire=VG or Disk) define inclusion/exclusion of file/dir/vg/disk
  • -a: tape drive address
  • -d: Description which will be displayed for archive
  • -i: Interactive execution

Since ignite is aimed at OS backup, normally we take VG00 i.e. root volume group’s backup only in Ignite tape backup. Let’s see one example :

# /opt/ignite/bin/make_tape_recovery -AvI -x inc_entire=vg00 -a /dev/rmt/0mn -x exclude=/data

=======  12/27/16 03:00:00 EDT  Started /opt/ignite/bin/make_tape_recovery.
         (Tue Dec 27 03:00:00 EDT 2016)
         @(#) Ignite-UX Revision B.4.4.12
         @(#) net_recovery (opt) $Revision: 10.611 $


       * Testing pax for needed patch
       * Passed pax tests.

----- output clipped -----

In the above example, we have started to ignite backup with all VG00 included (-x inc_entire=vg00), excluding /data mount point which is part of vg00 (-x exclude=/data), on tape drive at 0mn (-a /dev/rmt/0mn) with the interactive boot menu in the backup (-I). Verbose mode (-v) starts printing all outputs on the terminal screen as shown above.

It takes normally half an hour or more to complete backup depending on the size of your files included in the backup. If your terminal timeout is short value then you can put this command in the background (with below command) so that it won’t get killed when your terminal timed out and disconnect.

# /opt/ignite/bin/make_tape_recovery -AvI -x inc_entire=vg00 -a /dev/rmt/0mn -x exclude=/data >/dev/null 2>&1

Don’t worry all outputs are being logged to a log file so that you can analyze it later. Last few lines of output are as below which

declares backups has been completed successfully.

----- output clipped -----
       /var/tmp/ign_configure/make_sys_image.log
       /var/spool/cron/tmp/croutFNOa01327
       /var/spool/cron/tmp/croutBNOa01327
       /var/spool/cron/tmp/croutGNOa01327

       * Cleaning up old configuration file directories


=======  12/27/16 03:12:19 EDT make_tape_recovery completed successfully.

You can even schedule an Ignite backup in crontab on a monthly, weekly, or daily basis depending on your requirement.

Log files :

Your latest run output is saved under /var/opt/ignite/recovery/latest/recovery.log. All other run’s details are saved under  /var/opt/ignite/recovery directory. Whenever command runs it links the latest directory to the current run’s directory. See the below output to get an idea.

# ll /var/opt/ignite/recovery
total 14240
drwxr-xr-x   2 root       root          8192 Nov 27 03:12 2016-11-27,03:00
drwxr-xr-x   2 root       root          8192 Dec 27 03:12 2016-12-27,03:00
lrwxr-xr-x   1 root       sys             16 Dec 27 03:00 latest -> 2016-12-27,03:00
----- output clipped -----

If ignite fails then recovery.log is the first place to look for a reason for failure.

Troubleshooting :

This part is really hard to cover since there can be numerous reasons why Ignite fails. But let me cover few common reason here –

  1. Tape media is faulty (check EMS logs, Syslog)
    • Solution: media replacement
  2. The tape drive is faulty (check ioscan status, EMs, Syslog) 
    • Solution: hardware replacement
  3. One or more VG exist in /etc/lvmtab but not active on the system (verify /etc/lvmtab with bdf)
    • Solution: Remove inactive VG from lvmtab or made them active on the system
  4. One or more LVOLs  exist in /etc/lvmtab but not active on the system  (verify /etc/lvmtab with bdf)
    • Solution: Remove inactive lvol from lvmtab or mount them on system
  5. ERROR:   /opt/ignite/bin/save_config failed : One of the system attached disk/lun is faulty.
    • Solution: check hardware and replace it.

How to change process priority in Linux or Unix

Learn how to change process priority in Linux or Unix. Using the renice command understands how to alter the priority of running processes.

Processes in the kernel have their own scheduling priorities and using which they get served by the kernel. If you have a loaded system and need to have some processes serve before others you need to change process priority. This process is also called renicing since we use renice command to change process priority.

There are nice values defined from 0 to 20. 20 being the highest. The process with low nice values gets service before the process with a high nice value. So if you want a particular process to get served first you need to lower its nice value. Administrators may also choose to mark negative nice value (down up to -20) to speed up processes furthermore. Let’s see how to change process priority –

There are 3 ways to select a target for renice command. Once can submit process id (PID) or user ID or process group ID. Normally we use PID and UID in the real-world so we will see these options. New priority or nice value can be defined with option -n. Current nice value can be viewed in top command under NI column Or it can be checked using below command :

# ps -eo pid,user,nice,command | grep 30411
30411 root       0 top
31567 root       0 grep 30411

In above example, nice value is set to 0 for give PID.

Renice process id :

Process id can be submitted to renice using -p option. In below example we will renice value to 2 for pid 30411.

# renice -n 2 -p 30411
30411: old priority 0, new priority 2
# ps -eo pid,user,nice,command | grep 30411
  747 root       0 grep 30411
30411 root       2 top

renice command itself shows old and new nice values in output. We also verified new nice value using ps command.

Renice user id :

If you want to change priorities of all processes of a particular user then you can submit UID of that user using -u option. This option is useful when you want all processes by the user to complete fast, so you can set the user to -20 to get things speedy!

# ps -eo pid,user,nice,command | grep top
 3859 user4   0 top
 3892 user4   0 top
 4588 root    0 grep top
# renice -n 2 -u user4
54323: old priority 0, new priority 2
# ps -eo pid,user,nice,command | grep top
 3859 user4   2 top
 3892 user4   2 top
 4966 root    0 grep top

In the above example, there are two processes owned by user4 with priority 0. We changed the priority of user4 to 2. So both processes had their priority changed to 2.

Normal users can change their own process priority too. But he can not override priority set by the administrator. -20 is the lowest minimum nice value one can set on the system. This is the speediest priority, once set that process gets service and all available resources on the system to get its task done.