1. To test connection time:
1.1
$PASSWD="whatever"
$PASSED
get-content bosslist.txt|foreach-object {measure-command {(echo "select 1 from dual")|sqlplus jsun/$PASSWD@"(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(Host = $_)(Port = 1521))) (CONNECT_DATA = (SID =SIDNAME)))"}}|findstr TotalSeconds
output looks like this:
TotalSeconds
: 1.6875126
TotalSeconds
: 1.6090257
TotalSeconds
: 1.61322
...
1.2: This command will combine the server name to the totalseconds output.
get-content bosslist.txt|foreach-object {
$server=$_
measure-command {(echo "select 1 from dual")|sqlplus jsun/$PASSWD@"(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(Host = $_)(Port = 1521))) (CONNECT_DATA = (SID =PCP1)))"}
}|select-object {"Server "+$server+" : "+$_.TotalSeconds}
output look like this:
"Server "+$server+" : "+$_.TotalSeconds
---------------------------------------
Server server1 : 0.6284025
Server server2 : 0.9404446
Server server3 : 0.8597954
...
2. To find the database instance restart history for database name in racdb.txt:
get-content racdb.txt|foreach-object {(echo "SELECT db_name,instance_name, STARTUP_TIME FROM dba_hist_database_instance where STARTUP_TIME>sysdate-30 ORDER BY startup_time DESC;")|sqlplus jsun/$PASSWD@"(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(Host = scan.prd01.rac.bcferries.corp)(Port = 1521))) (CONNECT_DATA = (Service_name =$_.abcdomain.com)))" >> racdbrestart.txt}
3. To run sql script on all the servers:
get-content bosslist.txt|foreach-object {$_;sqlplus jsun/$PASSWD@$_ '@bossgrants.txt' }
4. To run sql script on multiple sqlserver:
get-content sqlserver.txt|foreach-object {osql -S $_ -E -i "c:\dropit\addlogin.sql" -o "c:\dropit\$_.txt"}
and then check the output file $_.txt
get-content sqlserver.txt|foreach-object {$_;get-content "c:\dropit\$_.txt"}
Comments
Post a Comment