Tuesday, June 7, 2016

echo $ - Shell Programming and Scripting

$_- The default parameter for a lot of functions. 
$.- Holds the current record or line number of the file handle that was last read. It is read-only and will be reset to 0 when the file handle is closed. 
$/- Holds the input record separator. The record separator is usually the newline character. However, if $/ is set to an empty string, two or more newlines in the input file will be treated as one. 
$,- The output separator for the print() function. Nor-mally, this variable is an empty string. However, setting $, to a newline might be useful if you need to print each element in the parameter list on a separate line. 
$\-- Added as an invisible last element to the parameters passed to the print() function. Normally, an empty string, but if you want to add a newline or some other suffix to everything that is printed, you can assign the suffix to $. 
$#-- The default format for printed numbers. Normally, it's set to %.20g, but you can use the format specifiers covered in the section "Example: Printing Revisited" in Chapter 9to specify your own default format. 
$%-- Holds the current page number for the default file handle. If you use select() to change the default file handle, $% will change to reflect the page number of the newly selected file handle. 
$=-- Holds the current page length for the default file handle. Changing the default file handle will change $= to reflect the page length of the new file handle. 
$- -- Holds the number of lines left to print for the default file handle. Changing the default file handle will change $- to reflect the number of lines left to print for the new file handle. 
$~-- Holds the name of the default line format for the default file handle. Normally, it is equal to the file handle's name. 
$^-- Holds the name of the default heading format for the default file handle. Normally, it is equal to the file handle's name with _TOP appended to it. 
$|-- If nonzero, will flush the output buffer after every write() or print() function. Normally, it is set to 0. 
$$-- This UNIX-based variable holds the process number of the process running the Perl interpreter. 
$?-- Holds the status of the last pipe close, back-quote string, or system() function. 
$&-- Holds the string that was matched by the last successful pattern match. 
$`- Holds the string that preceded whatever was matched by the last successful pattern match. 
$'-- Holds the string that followed whatever was matched by the last successful pattern match. 
$+-- Holds the string matched by the last bracket in the last successful pattern match. For example, the statement /Fieldname: (.*)|Fldname: (.*)/ && ($fName = $+); will find the name of a field even if you don't know which of the two possible spellings will be used. 
$*-- Changes the interpretation of the ^ and $ pattern anchors. Setting $* to 1 is the same as using the /m option with the regular expression matching and substitution operators. Normally, $* is equal to 0. 
$0-- Holds the name of the file containing the Perl script being executed. 
$<number>-- This group of variables ($1, $2, $3, and so on) holds the regular expression pattern memory. Each set of parentheses in a pattern stores the string that match the components surrounded by the parentheses into one of the $<number>variables. 
$[-- Holds the base array index. Normally, it's set to 0. Most Perl authors recommend against changing it without a very good reason. 
$]-- Holds a string that identifies which version of Perl you are using. When used in a numeric context, it will be equal to the version number plus the patch level divided by 1000. 
$"-- This is the separator used between list elements when an array variable is interpolated into a double-quoted string. Normally, its value is a space character. 
$;-- Holds the subscript separator for multidimensional array emulation. Its use is beyond the scope of this book. 
$!-- When used in a numeric context, holds the current value of errno. If used in a string context, will hold the error string associated with errno. 
$@-- Holds the syntax error message, if any, from the last eval() function call. 
$<- This UNIX-based variable holds the read uid of the current process. 
$>-- This UNIX-based variable holds the effective uid of the current process. 
$)-- This UNIX-based variable holds the read gid of the current process. If the process belongs to multiple groups, then $) will hold a string consisting of the group names separated by spaces. 
$:-- Holds a string that consists of the characters that can be used to end a word when word-wrapping is performed by the ^ report formatting character. Normally, the string consists of the space, newline, and dash characters. 
$^D-- Holds the current value of the debugging flags. For more information. 
$^F-- Holds the value of the maximum system file description. Normally, it's set to 2. The use of this variable is beyond the scope of this book. 
$^I-- Holds the file extension used to create a backup file for the in-place editing specified by the -i command line option. For example, it could be equal to ".bak." 
$^L-- Holds the string used to eject a page for report printing. 
$^P- This variable is an internal flag that the debugger clears so it will not debug itself. 
$^T-- Holds the time, in seconds, at which the script begins running. 
$^W-- Holds the current value of the -w command line option. 
$^X-- Holds the full pathname of the Perl interpreter being used to run the current script. 

Thursday, March 29, 2012

Commands to shutdown solaris10 machine

A solaris machine can be put to shutdown using the below mentioned commands .But use appropriate command that is required according to the need.


The commands are:-


1.shutdown
2.init
3.halt
4.reboot
5.poweroff
6.stop+A

1. Shutdown:- .This command is mostly used to shutdown server machines which consists of different users so that the users would be informed before shutting down the system. The default wait time for bringing the system to singler user state(root ) is 60 secs. In order to issue shutdown command one should have root priviliges.


   Syntax of Shutdown command with options.


    shutdown -i<init-state> -g<grace-period> -y


    where init-state can be 0,S,1,2,3,5,6. The default init-state  is S.


   where grace-period is to set the wait time of shutdown .The default time  is 60 secs.


  where  -y command  continues the shutdown with out prompting the meassage do you want to continue? (y or n)


2. Init :- This command is used to shutdown a single user system or change the runlevel of the system.
    
          syntax: init <run-level>




The below table describes about  different run-levels in detail



RUN LEVEL
 DESCRIPTION
0
Stops system services and daemons. Terminates all running processes. Unmounts all file systems.
S
System administatorr state. Only root is allowed to login.Only crictical file systems are monuted
1
System administatorr state. Only root is allowed to login. Local file sysytems are also mounted.
2
Normal multi-user operation state , without network file systems (NFSs)

3
Normal multiuse operation of a file server, with NFSs shared.

5
Power-down state. Shuts down the system so that it is safe to turn off power to the system.

6
Reboot state.


3.Halt:- This command shutdowns the sytem immediatley with out informing the users.


4.Reboot:- Reboots immediatley with  out informing the users .The speed of such a reboot is useful in certain circumstances, such as when you’re rebooting from the single-user run state and reconfigures the system.


example:-reboot -- -rs


5. Poweroff- Shutdowns the system with out notifying the users. If the hardware supports the power off it also turns off the power to system.


6.stop+A :Stop+A Interrupts any program currently running and puts the system at the OpenBoot prompt, ready to accept OpenBoot PROM commands.

Advantage of  shutdown and init over other commands:-


The Solaris reboot, poweroff, and halt commands stop the processor and synchronize the disks, but they perform unconditional shutdown of system processes. These commands are not recommended because they do not shut down any services and unmount any remaining file systems where as init and shutdown are the most reliable ways to shut down a system, because these commands shut down services in a clean, orderly fashion and shutdown the system with minimal data loss









Wednesday, March 14, 2012

Monitor Tuxedo Application using TXRPT utility

              txrpt utility


txrpt utility analyzes the standard error output of a Tuxedo server to provide a summary of service processing time within the server.


example1:-
cat tuxserver1.stderr.120115054310.29027 | txrpt
ili
 service summay report is printed for all the services of the tuxedo server"tuxserver1" where we can see summary is split into hourly report which contains response time of each service and number of times the service invoked.





  txrpt utility takes "std err" file of a particular tuxedo server as input where you can see each service's PID , Start Date, Start time , end time , end date (screen shot below) and analyses using some logic and converts to above output (screen shot above)








example2:-
cat tuxserver.stderr.120115054310.29027 | txrpt  -d 01/15 -s 11:00 -e 13:00

You can also take customized output from  txrpt utility  like you can specify on which date you need analysis , also you can give from which time to which time the report should be given.


Tuxedo administration - Cleaning IPC resources



                    Clean IPC resources


What are IPC resources:-Inter process communication resources are OS resources for example message queues, shared memory & semaphores. 


How tuxedo cleans IPC resources normally:-
Normally when tmshutdown command was issued to shutdown the tyxedo system it  removes all the  IPC resources from the system. 


What if tuxedo system doesnot clean IPC resources normally:-
But, if in case, shutdown was not successful , then few IPC resources will still remain in the system and this causes problem in tuxedo reboot next time.


How to clean IPC reources manually:-
tmipcrm [-y] [-n] [TUX_CONFIG_FILE]

Other methods of cleaning IPC reources manally:-

By listing the IPC resources first suing command ipcs
and then by removing them by command ipcrm


login to the tuxedo environment and fire below 3 commands ..

ipcs -s | grep $USER| awk '{printf "ipcrm -s %d\n", $2}' | sh
ipcs -m | grep $USER| awk '{printf "ipcrm -m %d\n", $2}' | sh
ipcs -q | grep $USER| awk '{printf "ipcrm -q %d\n", $2}' | sh

Monday, March 12, 2012

Service Management Facility(SMF) in Solaris10

Service Management Facility is a new feature added  to Solaris10. It has several advantages when compared with previous versions of solaris.

Some of the advantages are listed below.

1.SMF provides flexibility to root user to  view and manage services.
2. The system administrator can  also enable, disable , restart  and modify the system   services.
3. The dependency of  a service on other services are also maintained by SMF.
4. SMF  starts the services in correct order of their dependency.
5. SMF also starts the services in parallel according to the dependency so that the boot time is quicker than the previous versions of solaris.

Two important commands used in SMF are svcs and svcadm.

svcs :- Used to display information about all the services.

Common options used with svcs are :-

svcs  -a :-  Shows all the services
 example:-
legacy_run     Feb_28   lrc:/etc/rc2_d/S47pppd
legacy_run     Feb_28   lrc:/etc/rc2_d/S70uucp

disabled 15:48:41 svc:/network/shell:kshell
disabled 15:48:41 svc:/network/talk:default
disabled 15:48:42 svc:/network/apocd/udp:default
online 15:47:44 svc:/system/svc/restarter:default
online 15:47:47 svc:/network/pfil:default
online 15:47:48 svc:/network/loopback:default
online 15:47:50 svc:/system/filesystem/root:default


svcs  -d :- shows the dependent services.
 example:-
svcs -d svc:/network/ssh:default
STATE       STIME      FMRI
online         Feb_28    svc:/network/loopback:default
online         Feb_28    svc:/network/physical:default
online         Feb_28   svc:/system/cryptosvc:default
online         Feb_28   svc:/system/filesystem/local:default
online         Feb_28   svc:/system/utmp:default
online         Feb_28   svc:/system/filesystem/autofs:default

svcs -x :- Describes the state of the service.
   example:-
   svcs -x svc:/network/ssh:default
   svc:/network/ssh:default (SSH server)
   State: online since Tue Feb 28 16:01:46 2012
   See: sshd(1M)
   See: /var/svc/log/network-ssh:default.log
   Impact: None.



 svcs -l :- Displays detailed information about the service.
 example:-
svcs -l svc:/network/ssh:default
fmri         svc:/network/ssh:default
name         SSH server
enabled      true
state        online
next_state   none
state_time   Tue Feb 28 16:01:46 2012
logfile      /var/svc/log/network-ssh:default.log
restarter    svc:/system/svc/restarter:default
contract_id  61
dependency   require_all/none svc:/system/filesystem/local (online)
dependency   optional_all/none svc:/system/filesystem/autofs (online)
dependency   require_all/none svc:/network/loopback (online)
dependency   require_all/none svc:/network/physical (online)
dependency   require_all/none svc:/system/cryptosvc (online)
dependency   require_all/none svc:/system/utmp (online)
dependency   require_all/restart file://localhost/etc/ssh/sshd_config (online)

The state of each service can be one of the following

 disabled: The service instance is not enabled and is not running.
 legacy_run: The legacy service is not managed by the SMF, but the service can be
observed. This state is only used by legacy services that are started with RC scripts.
 maintenance: The service instance has encountered an error that must be resolved by
the administrator.
 offline: The service instance is enabled, but the service is not yet running or available
to run.
online: The service instance is enabled and has successfully started.
uninitialized: This state is the initial state for all services before their configuration
has been read.

svcadm is  Used to perform common service management tasks such as enabling, disabling, or restarting service instances.

The svcadm command allows the following sub commands

enable: Enables the service instances.
 example:-
 svcadm enable  svc:/network/swat/tcp:default

disable: Disables the service instances.
 example:-
svcadm disable svc:/network/swat/tcp:default

restart: Restarts the service instance
example:-
svcadm restart svc:/network/swat/tcp:default
 
 refresh: Refresh the service instance
 example :-
svcadm refresh  svc:/network/swat/tcp:default





Friday, March 9, 2012

Find out DB locks in a DB account or Instance and kill the process





 To find out the DB  lock on a particular DB account  




 To find out the DB  locks on all the Databases of a DB instance  




 To  create commands to kill the DB locked sessions  - fire below alter commands to kill 
respective DB sessions& locks       






Tuesday, March 6, 2012