Thursday, April 19, 2012

batch file to list the users in windows

1.Click Start
2.Click Run
3.Type: notepad and press enter.
4.Once notepad is open, type the below lines in the file or copy and paste the below lines into notepad.

@echo off
echo This Script will list the user

c:\WINDOWS\system32\net user "ASHRU"


pause


5.Click File and click Save; browse to where you want to save the file. For the file name, type "test.bat", and if your version of Windows has a "Save as type" option, choose "All files", otherwise it will save as a text file. Once all of this has been done click the Save button and exit notepad.
6.Now, to run the batch file, double-click or run the file like any other program. Once the batch file has completed running it will close the window automatically.

Batch file to set Virtual Memory in Windows

1.Click Start
2.Click Run
3.Type: notepad and press enter.
4.Once notepad is open, type the below lines in the file or copy and paste the below lines into notepad.


@echo off
echo This Script will set the virtual memory with an initial size and maximum size both of 4092 for both the C and D drives.
echo ashraf.mohammed@oracle.com

C:\WINDOWS\system32\pagefileconfig.vbs /change /I 4092 /M 4092 /VO C:

C:\WINDOWS\system32\pagefileconfig.vbs /change /I 4092 /M 4092 /VO D:
pause


5.Click File and click Save; browse to where you want to save the file. For the file name, type "test.bat", and if your version of Windows has a "Save as type" option, choose "All files", otherwise it will save as a text file. Once all of this has been done click the Save button and exit notepad.
6.Now, to run the batch file, double-click or run the file like any other program. Once the batch file has completed running it will close the window automatically.

Monday, April 16, 2012

script to check the preqreuiement of Oracle DB installation

# check sysctl
Check_Sysctl_Memstring()
{
FILE_MAX=""
FILE_MAX=`grep file-max /etc/sysctl.conf | grep ^fs.file-max | awk '{print $3}'`
if [ $FILE_MAX -eq 6815744 ];then
printf "%-80s %-20s\n\n" "fs.file-max is $FILE_MAX" "PASS" >> $OUT_FILE
else
printf "%-80s %-20s\n\n" "fs.file-max is $FILE_MAX, should be 6815744" "<>" >> $OUT_FILE
fi
}

# check swap
Check_Swap_Space()
{
SYS_SWAP=""
SYS_SWAP=`free -m | tail -1 | awk '{print $4}'`
if [ $SYS_SWAP -gt 16384 ]; then
printf "%-80s %-20s\n\n" "System swap is $SYS_SWAP, more than 16384MB" "PASS" >> $OUT_FILE
else
printf "%-80s %-20s\n\n" "System swap is $SYS_SWAP, less than 16384MB" "<>" >> $OUT_FILE
fi
}

# check EM agent

Check_EM_Agent()
{
# check if emagent is started
ps -ef | grep emagent >/dev/null 2>&1
if [ $? -eq 0 ]; then
printf "%-80s %-20s\n\n" "\"emagent\" is running" "PASS" >> $OUT_FILE
else
printf "%-80s %-20s\n\n" "\"emagent\" is not running" "<>" >> $OUT_FILE
fi
}


#
# port connectivity test
Check_Port_Connectivity()
{
if [ $# -eq 0 ]; then
echo "$ERROR_MISSINGARG"
echo " "
exit 1
fi


for myargs in "$@"
do
if [ $myargs = $ANALYTICS_HOST ]; then
echo " "
echo "checking port connectivity to $myargs on $PORT2 ..."
PORT_STATUS=`/usr/bin/nc -z -w 10 $myargs $PORT2 | awk '{print $7}'`
if [ "$PORT_STATUS" = "succeeded!" ]; then
printf "%-80s %-20s\n\n" "$myargs port $PORT2 accepting connections" "PASS" >> $OUT_FILE
else
printf "%-80s %-20s\n\n" "$myargs port $PORT2 connection failed" "<>" >> $OUT_FILE
fi
else
echo " "
echo "checking port connectivity to $myargs on $PORT1 ..."
PORT_STATUS=`/usr/bin/nc -z -w 20 $myargs $PORT1 | awk '{print $7}'`
if [ "$PORT_STATUS" = "succeeded!" ]; then
printf "%-80s %-20s\n\n" "$myargs port $PORT1 accepting connections" "PASS" >> $OUT_FILE
else
printf "%-80s %-20s\n\n" "$myargs port $PORT1 connection failed" "<>" >> $OUT_FILE
fi
fi
done
}


#
# check user ssh
# first time dsa keys are copied over, password prompt will be displayed
Check_User_SSH()
{
USER1=ororacrs
USER2=oraem
USER3=root
HOST1=fstlnx005

# run as oraem
su - $USER2 -c "ssh-copy-id -i ~/.ssh/id_dsa.pub $USER2@$HOST1" >/dev/null 2>&1
if [ $? -eq 0 ]; then
printf "%-80s %-20s\n\n" "Passwordless SSH for \"$USER2\"" "PASS" >> $OUT_FILE
else
printf "%-80s %-20s\n\n" "Passwordless SSH for \"$USER1\"" "<>" >> $OUT_FILE
fi


ssh-copy-id -i ~/.ssh/id_dsa.pub $USER3@$HOST1 >/dev/null 2>&1
if [ $? -eq 0 ]; then
printf "%-80s %-20s\n\n" "Passwordless SSH for \"$USER3\"" "PASS" >> $OUT_FILE
else
printf "%-80s %-20s\n\n" "Passwordless SSH for \"$USER3\"" "<>" >> $OUT_FILE
fi
}

# check SSH banner
Check_SSH_Banner()
{
SSH_BANNER=""
SSH_BANNER=`cat /etc/ssh/sshd_config | grep -i "#banner"`
if [ "`echo $SSH_BANNER | cut -c 1 | uniq`" = "#" ]; then
printf "%-80s %-20s\n\n" "SSH banner \"$SSH_BANNER\" commented out" "PASS" >> $OUT_FILE
else
printf "%-80s %-20s\n\n" "SSH banner NOT commented" "<>" >> $OUT_FILE
fi
}

Linux and Unix tee command

Linux and Unix tee command
Quick links

About tee
Syntax
Examples
Related commands
Linux and Unix main page

About tee

Read from an input and write to a standard output and file.

Syntax

tee [OPTION]... [FILE]...

-a
--append Append to the given FILEs, do not overwrite.
-i ignore interrupt signals.
--help Display the help screen.
--version Display the version.

Examples

ls *.txt | wc -l | tee /dev/tty count.txt

In the above example the ls command would list all .txt files in the current directory, take a word count (wc) by the amount of lines (-l) and the output displayed to the /dev/tty (terminal) will be sent to the count.txt.

Note: Because the above example did not take advantage of the -a or append option if the count.txt file already existed it would have been overwritten.

nc command to check port

/usr/bin/nc -z -w 10 vmsomxroa002.oracleoutsourcing.com 22
Connection to vmsomxroa002.oracleoutsourcing.com 22 port [tcp/ssh] succeeded!

cut command in linux

The cut command takes a vertical slice of a file, printing only the specified columns or fields. Like the sort command, the cut command defines a field as a word set off by blanks, unless you specify your own delimiter. It's easiest to think of a column as just the nth character on each line. In other words, "column 5" consists of the fifth character of each line. Consider a slight variation on the company.data file we've been playing with in this section:
406378:Sales:Itorre:Jan
031762:Marketing:Nasium:Jim
636496:Research:Ancholie:Mel
396082:Sales:Jucacion:Ed
If you want to print just columns 1 to 6 of each line (the employee serial numbers), use the -c1-6 flag, as in this command:
cut -c1-6 company.data
406378
031762
636496
396082
If you want to print just columns 4 and 8 of each line (the first letter of the department and the fourth digit of the serial number), use the -c4,8 flag, as in this command:
cut -c4,8 company.data
3S
7M
4R
0S
And since this file obviously has fields delimited by colons, we can pick out just the last names by specifying the -d: and -f3 flags, like this:
cut -d: -f3 company.data
Itorre
Nasium
Ancholie
Jucacion
It's often the case that you want to use a space as the delimiter. To do so, you must put the delimiter in single quotes, like this: -d' '
Also, when you want to cut from a starting point to the end of the line, just leave off the final field number, as shown in the example below.
Let's say this is your test.txt file:
abc def ghi jkl
mno pqr stu vwx
yz1 234 567 890
To cut only columns 2-END, do this: cut -d' ' -f2- test.txt
And the results are:
def ghi jkl
pqr stu vwx
234 567 890
Here is a summary of the most common flags for the cut command:
-c [n | n,m | n-m] Specify a single column, multiple columns (separated by a comma), or range of columns (separated by a dash).
-f [n | n,m | n-m] Specify a single field, multiple fields (separated by a comma), or range of fields (separated by a dash).
-dc Specify the field delimiter.
-s Suppress (don't print) lines not containing the delimiter.

Send mail using Shell Script

Include the below line in the script which you are writing ,so that the file ,which in this case called as OUT_FILE will be sent to the email given .

cat $OUT_FILE | mail -s "DB_Pre_check" ashraf.mohammed@oracle.com

To check the status of email service

service sendmail status
sendmail (pid 1661) is running...

The /etc/mail/sendmail.mc File You can define most of sendmail's configuration parameters in the /etc/mail/sendmail.mc file, which is then used by the m4 macros to create the /etc/mail/sendmail.cf file. Configuration of the sendmail.mc file is much simpler than configuration of sendmail.cf, but it is still often viewed as an intimidating task with its series of structured directive statements that get the job done. Fortunately, in most cases you won't have to edit this file very often.

How to Put Comments in sendmal.mc In most Linux configuration files a # symbol is used at the beginning of a line convert it into a comment line or to deactivate any commands that may reside on that line.

The sendmail.mc file doesn't use this character for commenting, but instead uses the string "dnl". Here are some valid examples of comments used with the sendmail.mc configuration file:

These statements are disabled by dnl commenting.
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')

This statement is incorrectly disabled:
# DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
This statement is active:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
Note: Remember to run the activate-sendmail.sh script to activate any configuration changes.

Monday, April 9, 2012

Configuring JConsole for weblogic

Configuring JConsole for WebLogic 11g JDK 1_6_0_18

Follow the steps given below to configure JConsole from a remote machine for weblogic 11g jdk1.6 ..

It is always better to access Jconsole from a remote server ,to reduce the impact of jconsole application itself on the server ..


1. Take a backup of setDomainEnv.sh file
2. Edit the setDomainEnv.sh file (/wls/Oracle/Middleware/user_projects/domains//bin) to include JAVA_OPTIONS as given below ,make sure the port 1616 is not used by any other application.


JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1616 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
export JAVA_OPTIONS

3. check wehtet the port 1616 is opened or not .It should be open ..
[root@ausomxa3s04 bin]# netstat -anp |grep 1616
tcp 0 0 :::1616 :::* LISTEN 13882/java

4. Save the file

5. Restart the Admin server or managed server which ever you want to monitor .
6. Open the Jconsole from a remote server for example from this location D:\oracle\product\weblogic11g\jdk160_18\bin of a windows machine .


Trouble shooting ..


I am having problem using JConsole to connect to a JVM running on Linux. Connecting to JVM running on Windows and Solaris works fine.
This is most likely a configuration problem on the Linux machine or the management properties specified to run the application. Please also see FAQ #4 about using SSL.

You should check the following:

Check if the hostname correctly resolves to the host address.
Run "hostname -i" command. If it reports 127.0.0.1, JConsole would not be able to connect to the JVM running on that Linux machine. To fix this issue, edit /etc/hosts so that the hostname resolves to the host address.

Check if the Linux machine is configured to accept packets from the host where JConsole runs on to connect to the application.
Packet filtering is built in the Linux kernel. You can run "/sbin/iptables --list" to determine if an external client is allowed to connect to the JMX agent created for remote management. You can use the following command to add a rule to allow an external client such as JConsole to connect:

/usr/sbin/iptables -I INPUT -s jconsole-host -p tcp --destination-port jmxremote-port -j ACCEPT

where jconsole-host is either the hostname or the host address on which JConsole runs on and jmxremote-port is the port number set for com.sun.management.jmxremote.port for remote management.