Custom Search

Saturday, November 15, 2014

Powershell script to checking event viewer for exceptions remotely then send email and restart the windows service.

Powershell script for checking any specific file or event viewer for exceptions remotely then send email and restart the windows service.
===============================================================================================================================

This script is for Checking "OutOfMemoryException" or any type of exception in the windows server/machine and then it will send email notification and then restart the respective service.
example: In our case, we have a old service program, which is running on windows and we haven't source code of this one. so after running few days it is stopped by ourofmemory exception. sometime we couldn't know when it was stopped how many days it was stopped. but it should run 24/7 hours.
         so after geting informed that it is not running then someone needs to start it manually. (it is also a problem at night or weekend time). so i wrote this script and it solved our problem. but now we are trying to build a new one. it will take time.



1) create a powershell script (.ps1) file with this follwing code like,  script_for_outofmemory.ps1


=============================================================================================================================================================
 #### For Checking in the event viewer of windows for "OutOfMemoryException"  
 $a = Get-EventLog -LogName "Application" -computername remote_machine_name -After (Get-Date).AddMinutes("-30") | Where-Object {$_.Source-like "*ExceptionManagerPublishedException*"} | Where-Object {$_.EntryType-eq "Error"} | Where-Object {$_.Message -like "*OutOfMemoryException*"}  
 #### following line is for Checking in a specific file of windows for "OutOfMemoryException"  
#### $a = Get-Content -Path \\machine_name\d$\ErrorLog\log.txt | Select-String System.OutOfMemoryException  
  if ($a -ne $Null)  
   {  
     "OutOfMemoryException is found in log.txt within 60 minutes and checking for restart"  
     #-----checking for re-start within 30 minutes begin----  
     $r = Get-EventLog -LogName "Application" -computername machine_name -After (Get-Date).AddMinutes("-30") |Where-Object {$_.Source-like "*TomcatService*"} | Where-Object {$_.EntryType-eq "Information"} | Where-Object {$_.Message -like "*Service Start*"}  
        if ($r -ne $Null)  
           {  
             "Restart found within 30 minutes, Tomcat Service is restarted by someone"  
           }  
       ELSE  
           {  
               "Restart not found, Sending email tomcat service needs to be Restarted"  
               ## email sending----------------  
               $emailFrom = "Halim@test.com"  
               # Use commas for multiple addresses  
               $emailTo = "user1@test.com,user2@test.com"  
               $subject = "(Tomcat Auto-restart script) Tomcat service needs to be Restarted"  
               $body = "(Tomcat Auto-restart script): Cause: The Tomcat server encountered System Out of Memory Exception in errlog.txt. This exception can be seen in \\machine_name\d$\ErrorLog\log.txt"  
               $smtpServer = "smtp_server_ip_or_name"  
               $smtp = new-object Net.Mail.SmtpClient($smtpServer)  
               $smtp.Send($emailFrom, $emailTo, $subject, $body)   
               #----checking service status then stop and start begin  
               #-------------------------------------------------------------------------------------------------  
               "Checking status of TomcatDocumentService....."  
               $s=get-service -Name TomcatDocumentService -ComputerName Machine_name_Tomcat  
               $s.Status  
                 if ($s.Status -eq 'Stopped')  
                   {  
                   "found TomcatDocumentService Service is stopped"  
                ############ Service start command   
                   Get-Service -Name TomcatDocumentService -ComputerName Machine_name_Tomcat | Set-Service -Status Running  
                     ## email sending----------------  
                   $emailFrom = "Halim@test.com"  
                   # Use commas for multiple addresses  
                   $emailTo = "user1@test.com,user2@test.com"  
                   $subject = "(Tomcat Auto-restart script) Tomcat service has been Restarted Successfully"  
                   $body = "(Tomcat Auto-restart script): Cause: The Tomcat server encountered System Out of Memory Exception in errlog.txt. This exception can be seen in \\machine_name\d$\ErrorLog\log.txt. Please Check and take appropriate action manually!."  
                   $smtpServer = "smtp_server_ip_or_name"  
                   $smtp = new-object Net.Mail.SmtpClient($smtpServer)  
                   $smtp.Send($emailFrom, $emailTo, $subject, $body)   
                   }  
                 ELSE  
                    {  
                   "Found TomcatDocumentService service is running "  
                ############ Service stop command   
                  Get-Service -Name TomcatDocumentService -ComputerName Machine_name_Tomcat | Set-Service -Status Stopped  
                   #---------wait 2 minutes and check status begin  
                   "Waiting 8 minutes......start point "  
                   Start-Sleep -Seconds 480 #---wait 8 minutes  
                   "Waiting 8 minutes......end point "  
                   #-----------------------------again check status begin  
                   "Re-checking service TomcatDocumentService...."  
                       $ss=get-service -Name TomcatDocumentService -ComputerName Machine_name_Tomcat  
                        $ss.Status  
                       if ($ss.Status -eq 'Stopped')  
                         {  
                         "TomcatDocumentService service found stopped in re-check"  
                ############ Service start command   
                     Get-Service -Name TomcatDocumentService -ComputerName Machine_name_Tomcat | Set-Service -Status Running  
                         ## email sending----------------  
                     $emailFrom = "Halim@test.com"  
                     # Use commas for multiple addresses  
                    $emailTo = "user1@test.com,user2@test.com"  
                         $subject = "(Tomcat Auto-restart script) Tomcat service has been Restarted Successfully"  
                         $body = "(Tomcat Auto-restart script): Cause: The Tomcat server encountered System Out of Memory Exception in errlog.txt. This exception can be seen in \\machine_name\d$\ErrorLog\log.txt. Please Check and take appropriate action manually!."  
                         $smtpServer = "smtp_server_ip_or_name"  
                         $smtp = new-object Net.Mail.SmtpClient($smtpServer)  
                         $smtp.Send($emailFrom, $emailTo, $subject, $body)   
                         }  
                       ELSE  
                         {  
                          ## email sending----------------  
                     $emailFrom = "Halim@test.com"  
                     # Use commas for multiple addresses  
                     $emailTo = "user1@test.com,user2@test.com"  
                         $subject = "(Restart script) Tomcat service needs to be restarted, but the script could not stop the process. Pls. check and take appropriate action manually."  
                         $body = "(Tomcat Auto-restart script): The Tomcat server encountered System Out of Memory Exception in errlog.txt. This exception can be seen in \\machine_name\d$\ErrorLog\log.txt. Please check and take necessary action as soon as possible."  
                         $smtpServer = "smtp_server_ip_or_name"  
                         $smtp = new-object Net.Mail.SmtpClient($smtpServer)  
                         $smtp.Send($emailFrom, $emailTo, $subject, $body)   
                         }  
                     }  
             }  
 }  
 ELSE  
 {  
  "Tomcat is running fine"  
 }  

=========================================================================================================================================================


2) Create a schedule job with you desire interval via passing below action parameter
  Note: create the job with privileage user (execute as a different user).


Powershell.exe -executionpolicy remotesigned -File C:\halim_documents\script_for_outofmemory.ps1


note: (For invoking windows powershell.exe from remote machine and with different user, you can {press shift + right click on windows powershell.exe} then click on "run as diferent user" put user_name and password



Friday, October 31, 2014

H1b visa to work in USA, Especially for IT professional

Info about H1b visa to work in USA, Especially for IT professional,

I am getting lots of email about H1b visa. How can we apply for this visa? I also have seen one of Bangladeshi newspaper published wrong information about H1b visa and a website linked in it, asking money for providing information only. Through I am replying individually, but I thought, I will write something details about this and share with you so that you can get informed and benefited.

H1b visa can be a very good opportunity for Bangladeshi IT (Computer engineer) talents to work in USA. Lots of Indian (south Indian) and Chines professionals are coming to USA with this visa every year. So it could be a good job source also for Bangladeshi High skilled computer engineers. As per my knowledge, there are lots of world qualities IT professional in Bangladesh and I believe Bangladeshi’s are not less genius than others.  

The US H1B visa is a non-immigrant visa that allows US companies to employ foreign workers in specialty occupations that require theoretical or technical expertise in specialized fields such as in Computer engineering, architecture, others engineering, mathematics, science, and medicine. Under the visa a US company can employ a foreign worker for up to six years at least. (3 years + 3 years extension). Then if there are not enough employees like you in US market then you can apply for Green Card.

H1B visa applications can only be filed by the US employer (not the individual/beneficiary). Foreign Nationals MUST first obtain an H1B sponsorship job (sponsored employment position) with a US employer who will hire them and file for their H1B visa. (Now easy to find out but you have to more qualify for that)

Current immigration law allows for a total of 85,000 new H-1B visas to be made available each government fiscal year. This number includes 65,000 new H-1B visas issued for overseas workers in professional or specialty occupation positions, and an additional 20,000 visas available for those with an advanced degree from a US academic institution. Once the visa cap has been reached, USCIS will stop accepting H-1B petitions for this year. If more application applied within a time frame then a lottery will happen for selecting 65,000 candidates and 20000 candidates.

HIB visa season starts on April 1st of every year. Usually USCIS starts accepting H1B visa petitions for next fiscal year starting from April 1st of the current year. So you need to make sure, everything is ready by before April 1st. For The Bangladeshi, only hard thing is to find out a H1B Visa sponsoring companies or US employers who are willing to sponsor.

1) Find out the sponsoring companies.

For searching on H1B Visa sponsoring companies. You can create a list of all the companies that are likely to sponsor H1B Visa for your profile. Send an attractive email to all of them with your experience, ability, success and more (with a good resume also) . Read article :  How to find H1B Visa 2015 Sponsors. You can use  H1B Visa Sponsors Database    and (http://www.myvisajobs.com/Search_Visa_Sponsor.aspx) links to look for companies that sponsor H1B visas in a particular City or Zipcode or Occupation or by company name. You will apply for jobs during this period with these companies and do job interviews with the companies. Think of this period as intensive job search.

2) Verify the H1B Visa Sponsoring companies

3) Finalize the H1B Sponsoring company

4) You need to work with your employer and their attorney for filing H1B petition. You will need to send the documents, usually only scan copies of the documents are requested by attorney. Do NOT provide any origianls.

5) Send out all the scan copies via email. If anything required as hard copy, just courier the same.  It is critical that you work with your attorney and have it ready so that they file for your LCA during this week itself.

6) You need to check with your attorney and employer, if they have all the documents and everything is on track. This is the busiest time for employers and attorneys. If everything went well and your attorney has all the paperwork, there is no activity for you.


DON'T SEND ANY MONEY FOR CHARGE OF ANY FEES!

FYI-   Now USA job market is good for IT professionals.

For more info,
How can you Apply H1B Visa

http://redbus2us.com/category/h1b-visa-consulting/apply-h1b-visa-h1b-visa-consulting/

http://blog.upcounsel.com/how-can-a-startup-sponsor-an-h1b-visa/

How to find out H1B visa Sponsor companies

http://www.myvisajobs.com/Search_Visa_Sponsor.aspx

http://www.myvisajobs.com/H1B-Visa/SearchLCA.aspx?Y=2013&E=tata&O1=Employer&O2=JobTitle

http://www.immihelp.com/h1b-sponsoring-companies-database/


How to find companies, Avoid Fraud ?

http://redbus2us.com/h1b-visa-2014-sponsors-how-to-find-companies-avoid-fraud/

H1B Visa 2015 – Frequently Asked Questions
http://redbus2us.com/h1b-visa-2015/


For any clarification and more information, anyone can shoot me email or send me message.

Thursday, October 16, 2014

ORA-15183: ASMLIB initialization error [driver/agent not installed] in oracle database at linux server.



ORA-15183: ASMLIB initialization error [driver/agent not installed]

After reinstalling grid infrastructure and oracle software  or applying patch (PSU) in linux server. You may face below error (and in alert log ORA-15183 error) when you will try to startup the oracle database.
Only three command give you the solution.  Solution is below.


SQL>
SQL> host rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Wed Oct 15 15:05:21 2014

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup     

Oracle instance started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 10/15/2014 15:05:41
ORA-03113: end-of-file on communication channel
Process ID: 16205
Session ID: 199 Serial number: 44057

RMAN> shutdown immediate

using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of shutdown command at 10/16/2014 10:23:44
RMAN-12001: could not open channel default
RMAN-10008: could not create channel context
RMAN-10005: error opening cursor
RMAN-10002: ORACLE error: ORA-03114: not connected to ORACLE

RMAN> exit






Alert log content:

NOTE: ASMB registering with ASM instance as Standard client 0xffffffffffffffff (reg:4060941312) (new connection)
Wed Oct 15 15:05:37 2014
Errors in file /userdata/app/oracle/diag/rdbms/icmsdb1/ICMSDB/trace/ICMSDB_rbal_16178.trc:
ORA-15183: ASMLIB initialization error [driver/agent not installed]
Wed Oct 15 15:05:37 2014
WARNING: FAILED to load library: /opt/oracle/extapi/64/asm/orcl/1/libasm.so
Wed Oct 15 15:05:37 2014
starting up 1 shared server(s) ...
Wed Oct 15 15:05:37 2014
NOTE: ASMB connected to ASM instance +ASM osid: 16186 (Flex mode; client id 0xffffffffffffffff)
NOTE: initiating MARK startup
Starting background process MARK
Wed Oct 15 15:05:37 2014
MARK started with pid=27, OS id=16192
Wed Oct 15 15:05:37 2014
NOTE: MARK has subscribed
ORACLE_BASE from environment = /userdata/app/oracle
Wed Oct 15 15:05:39 2014
alter database mount
Wed Oct 15 15:05:40 2014
NOTE: ASMB mounting group 1 (DATA)
Wed Oct 15 15:05:40 2014
WARNING: cellinit.ora is missing. RBAL is terminating the instance.
RBAL (ospid: 16178): terminating the instance due to error 27625
Wed Oct 15 15:05:41 2014
System state dump requested by (instance=1, osid=16178 (RBAL)), summary=[abnormal instance termination].
System State dumped to trace file /userdata/app/oracle/diag/rdbms/icmsdb1/ICMSDB/trace/ICMSDB_diag_16152_20141015150541.trc
Wed Oct 15 15:05:41 2014
Dumping diagnostic data in directory=[cdmp_20141015150541], requested by (instance=1, osid=16178 (RBAL)), summary=[abnormal instance termination].
Wed Oct 15 15:05:41 2014
Instance terminated by RBAL, pid = 16178








Cause:

This is an Ownership issue. After reinstalling grid and oracle software, or applying Patch, it changed the group (ASMADMIN) to (OINSTALL) for ORACLE user and   $ORACLE_HOME/bin folder. So now you have to change the group back again to ASMADMIN and give appropriate permission also.
Solution:

With root user :-

[oracle@icms-test-db-st bin]$
[oracle@icms-test-db-st bin]$
[oracle@icms-test-db-st bin]$ su - root
Password:
[root@icms-test-db-st ~]#
[root@icms-test-db-st ~]#
[root@icms-test-db-st ~]# cd $ORACLE_HOME/bin
[root@icms-test-db-st bin]#
[root@icms-test-db-st bin]# chgrp asmadmin oracle
[root@icms-test-db-st bin]#
[root@icms-test-db-st bin]# chmod 6751 oracle
[root@icms-test-db-st bin]#
[root@icms-test-db-st bin]#



After that Database will be startup ..

SQL>
SQL>
SQL>
SQL> host rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Thu Oct 16 10:24:01 2014

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup mount ;

Oracle instance started
database mounted

Total System Global Area    4110417920 bytes

Fixed Size                     2932096 bytes
Variable Size               2197815936 bytes
Database Buffers            1895825408 bytes
Redo Buffers                  13844480 bytes

RMAN>



Wednesday, September 17, 2014

Enq: TM - contention waits in oracle database and solution !

Today I was noticed that, one delete (5 rows ) statement taking so much time in a particular table only. then I looked into it, found  "Enq: TM - contention" waits taking times .....
In this table there is a foreign key relationship with other table.
and  "Enq: TM - contention" indicate there are unindexed foreign key constraints. so I just created an index on that foreign key column or columns (in foreign table) it solved the problem.

Here is a script that can find  unindexed foreign key constraints for a specific user .....

SELECT * FROM (
SELECT c.table_name, cc.column_name, cc.position column_position
FROM   user_constraints c, user_cons_columns cc
WHERE  c.constraint_name = cc.constraint_name
AND    c.constraint_type = 'R'
MINUS
SELECT i.table_name, ic.column_name, ic.column_position
FROM   user_indexes i, user_ind_columns ic
WHERE  i.index_name = ic.index_name
)
ORDER BY table_name, column_position;

Saturday, December 21, 2013

How to send a email if any ERROR occurs in oracle database alert log files in oracle 10g, 11g, 12c. Steps

 1) Create a external table for the alert log content.  
  How to create external table for alert log.  
 2) Create a view from this external table like...  
 ---------------------------------------------------------  
   CREATE OR REPLACE FORCE VIEW DBA_MAIN.VW_ALERT_LOG  
 (  
   NO_OF_LINE,  
   TEXT  
 )  
 AS  
   SELECT NO_of_line, text  
    FROM ( SELECT ROWNUM NO_of_line, text  
         FROM dba_main.alert_log_external  
       ORDER BY ROWNUM DESC)  
   WHERE UPPER (text) LIKE UPPER ('%ERROR%')   
 /  
 -----------------------------------------------------------  
 3) Create a table from this above view like....  
 -------------------------------------------------------------  
 CREATE TABLE DBA_MAIN.TBL_ALERT_LOG_ERROR  
 AS  
   SELECT No_of_line, text, 'Y' send_flg FROM DBA_MAIN.VW_ALERT_LOG;  
 ---------------------------------------------------------------  
 3) Create a email address table and insert some email addresses like below...  
 ------------------------------------------------------------  
 CREATE TABLE DBA_MAIN.EMAIL_ADDRESS  
 (  
  ID    NUMBER,  
  NAME   VARCHAR2(50 BYTE),  
  EMAIL   VARCHAR2(100 BYTE),  
  ACT_FLAG VARCHAR2(1 BYTE)          DEFAULT 'Y'  
 ) ;  
 Insert into DBA_MAIN.EMAIL_ADDRESS  
   (ID, NAME, EMAIL, ACT_FLAG)  
  Values  
   (1, 'Abdul Halim', 'halim@test.com', 'Y');  
 Insert into DBA_MAIN.EMAIL_ADDRESS  
   (ID, NAME, EMAIL, ACT_FLAG)  
  Values  
   (2, 'user2', 'test@test.com', 'N');  
 Insert into DBA_MAIN.EMAIL_ADDRESS  
   (ID, NAME, EMAIL, ACT_FLAG)  
  Values  
   (3, 'user1', 'test2@test.com', 'N');  
 COMMIT;  
 4) Create a package for sending email from the oracle database   
 (In this package, i created two procedures , one for sending email with attachment   
 another is sending email without attachment ment. I am using first one here)  
 -------------------------------------------------------------  
 SEND_EMAIL_FROM_PL_SQL.send_email_with_attachment  
 -----------------------------------------------------------  
 4) create belows trigger on "DBA_MAIN.TBL_ALERT_LOG_ERROR" this table..  
 --------------------------------------------------------------------------  
 CREATE OR REPLACE TRIGGER DBA_MAIN.TRG_ALERT_LOG_ERROR_EMAIL  
 before INSERT ON DBA_MAIN.TBL_ALERT_LOG_ERROR  
 REFERENCING NEW AS new     
 FOR EACH ROW  
 WHEN (  
 new.send_flg='N'  
    )  
 begin  
 /*  
  SEND_EMAIL_FROM_PL_SQL.send_email_with_attachment  
     ( sender_email_address     varchar2, -- Must be single E-mail address  
      recipient_email_addresses  varchar2,   
      email_subject        varchar2,  
      email_body_text       varchar2,  
      email_attachment_text    clob,   -- No restriction on size of text  
      email_attachment_file_name  varchar2    
     )  
    */  
  for i in (select email from dba_main.email_address where act_flag='Y') loop   
  SEND_EMAIL_FROM_PL_SQL.send_email_with_attachment  
     ( 'halim@test.com', -- Must be single E-mail address  
      i.email,      'Test Email from Database!',  
      'Plz check the Alert for more info.... ' || :new.text,  
      :new.text,   -- No restriction on size of text  
      'Attention'   
     ) ;  
     end loop;  
 end;  
 /  
 -------------------------------------------------------------------------  
 5) create a procedure...for job....  
 ---------------------------------------------------------  
 CREATE OR REPLACE PROCEDURE dpr_alter_log_error_marge  
 IS  
 BEGIN  
   MERGE INTO TBL_ALERT_LOG_ERROR f_table  
     USING DBA_MAIN.VW_ALERT_LOG v_table  
       ON (v_table.text = f_table.text) --- and UPPER (v_table.text) LIKE UPPER ('%ERROR%') )  
   WHEN MATCHED  
   THEN  
    UPDATE SET f_table.SEND_FLG = 'Y'  
   WHEN NOT MATCHED  
   THEN  
    INSERT   (NO_OF_LINE, TEXT, SEND_FLG)  
      VALUES (ROWNUM, v_table.text, 'N');  
 END;  
 ----------------------------------------------------------  
 6) create a job like belows ( it will check alert log error and if found then send it email to DBA..  
 -----------------------------------------------------------  
 DECLARE  
  X NUMBER;  
 BEGIN  
  SYS.DBMS_JOB.SUBMIT  
  ( job    => X   
   ,what   => 'DBA_MAIN.DPR_ALTER_LOG_ERROR_MARGE;'  
   ,next_date => to_date('20/12/2013 10:55:34','dd/mm/yyyy hh24:mi:ss')  
   ,interval => 'SYSDATE+60/1440 '  
   ,no_parse => FALSE  
  );  
  SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));  
 COMMIT;  
 END;  
 /  
 ------------------------------------------------------------