출처 : https://blog.fabioiotti.com/ip-address-batch/


This is a way to get the computer's IP address from a Batch script with a single line of code. Jump to TL;DR for the copy-paste ready code.

So... what do we need the IP address of this computer for? Do we need the our network address or our public address?

Getting Local IP Address

If the IP we need is the internal address (the one within current network's boundaries), we can ask our local DNS server (which knows our machine and our address). Local DNS server is running inside our router.

The correct way to proceed would be to run ipconfig command and parse it's output, then handpick from the list of results the address we actually want.

What if we want this procedure to be completely automatic? Then we have two options: ask the DNS server with nslookup command; or use local cache with pingcommand. What we will be doing is ping our own machine and see what Windows decided to be the best address to use.

We will use ping command to ping our local machine using IPv4 and sending only one packet. Since pinging the local machine, this operation should not halt and should never fail. When offline, this command will ping 127.0.0.1.

C:\Users\User>ping -4 -n 1 %ComputerName%  
Pinging MY-COMPUTER [192.168.1.139] with 32 bytes of data:  
Reply from 192.168.1.139: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.1.139:  
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:  
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

Let's first check what happens if our locale is not English...

C:\Users\User>ping -4 -n 1 %ComputerName%  
Esecuzione di Ping MY-COMPUTER [192.168.1.139] con 32 byte di dati:  
Risposta da 192.168.1.139: byte=32 durata<1ms TTL=128

Statistiche Ping per 192.168.1.139:  
    Pacchetti: Trasmessi = 1, Ricevuti = 1,
    Persi = 0 (0% persi),
Tempo approssimativo percorsi andata/ritorno in millisecondi:  
    Minimo = 0ms, Massimo =  0ms, Medio =  0ms

We can extract the line with the IP inside square brackets by piping the results into findstr command.

C:\Users\User>ping -4 -n 1 %ComputerName% | findstr "["  
Pinging MY-COMPUTER [192.168.1.139] with 32 bytes of data:  

And finally, we can discard anything outside of the brackets.

C:\Users\User>for /f "delims=[] tokens=2" %a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do echo %a  
192.168.1.139  

Do we need this code to be Batch? Let's create a local_ip.bat file with the following contents…

@echo off

for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set ThisIP=%%a

echo %ThisIP%  

And we are done. 😄

Note: all this commands are available since Windows XP and we never rely on localized strings, we can thus use this script anywhere.

Getting Public IP Address

If we need the public address of the outer machine in current network, then we need to ask for a little help from the outside: we have to call an external service and ask where they see our request coming from.

We well be using the free ipify service.

C:\Users\User>powershell Invoke-RestMethod api.ipify.org  
188.216.217.9  

Note: I also tried with nslookup myip.opendns.com. resolver1.opendns.com command but it didn't prove reliable as it failed in some of my networks.

Same as before: let's make this a Batch script. Name it public_ip.bat and paste the following code…

@echo off

for /f %%a in ('powershell Invoke-RestMethod api.ipify.org') do set ThisIP=%%a

echo %ThisIP%  

Note: unlike the script to read network IP address, this one relies on PowerShellwhich is only included since Windows 7. This script will thus not work on Windows XPand Vista out of the box.

Thanks for reading, I hope this guide will prove useful to you. Feel free to leave a comment in the section below! 😁


TL;DR

@echo off

for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set NetworkIP=%%a

for /f %%a in ('powershell Invoke-RestMethod api.ipify.org') do set PublicIP=%%a

echo Network IP: %NetworkIP%  
echo Public IP: %PublicIP%  

References

https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/nslookup.mspx?mfr=true

https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/findstr.mspx?mfr=true

https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ping.mspx?mfr=true

http://stackoverflow.com/q/5898763/1135019


블로그 이미지

레몬도리 LemonDory

개발자의 이야기

var collectionNames = db.getCollectionNames();
for(var i = 0, len = collectionNames.length; i < len ; i++){
    var collectionName = collectionNames[i];
    if(collectionName.indexOf('cache_') == 0){
        db[collectionName].drop()
    }
}

출처 : http://stackoverflow.com/questions/12844531/mongodb-removing-all-collections-whose-name-matches-a-string


db.getCollectionNames().forEach(function(collection) {

   indexes = db[collection].getIndexes();

   print("Indexes for " + collection + ":");

   printjson(indexes);

}); 






블로그 이미지

레몬도리 LemonDory

개발자의 이야기

What you want is:

 mongo sm-repository2.db.qa.test.com:27017/testdb --eval "db.stats()"

Or for longer scripts:

 mongo sm-repository2.db.qa.test.com:27017/testdb script.js


출처 : http://stackoverflow.com/questions/4837673/how-to-execute-mongo-commands-through-shell-scripts

블로그 이미지

레몬도리 LemonDory

개발자의 이야기

Insert

// 한개

db.getCollection('restaurants').insert( { item: "box", qty: 20 } ) 

// 여러개
db.getCollection('restaurants').insert(    [
     { _id: 11, item: "pencil", qty: 50, type: "no.2" },
     { item: "pen", qty: 20 },
     { item: "eraser", qty: 25 }
   ] )

Update

db.books.update(
   { item: "XYZ123" },
   {
     item: "XYZ123",
     stock: 10,
     info: { publisher: "2255", pages: 150 },
     tags: [ "baking", "cooking" ]
   }
)

위와 같이 명령을 실행하면 한개의 데이터만 변경된 것을 확인할 수 있다.

여러 개를 바꾸려면 아래와 같이 인자를 추가해준다.

db.books.update(
   { item: "XYZ123" },
   {
     item: "XYZ123",
     stock: 10,
     info: { publisher: "2255", pages: 150 },
     tags: [ "baking", "cooking" ]
   }
   { multi: true }
)

Delete

 db.bios.remove( { } )

모든 데이터 삭제

 db.products.remove( { qty: { $gt: 20 } }, true )

일치 데이터 삭제

블로그 이미지

레몬도리 LemonDory

개발자의 이야기

Stairway to SQL Server Replication


SQL Replication can solve many problems in running database-driven applications. The publication/subscriber model isn't completely easy to understand, the complexities of scripting and monitoring replication systems takes some thought. Here, at last, is a series of articles that takes care to produce a jargon-free approach to SQL Server Replication of all types.

Stairway to SQL Server Replication: Level 1 - Introduction to SQL Server Replication

In this Stairway, Sebastian will be covering the details of SQL Server transactional and merge replication, from understanding the basic terminology and methodology of setting up replication, to describing how it works and how the basic replication processes can be monitored.   Read more...

Stairway to SQL Server Replication: Level 2 - The Role of the Distributor

In this Stairway, Sebastian will be covering the details of SQL Server transactional and merge replication, from understanding the basic terminology and methodology of setting up replication, to describing how it works and how the basic replication processes can be monitored.   Read more...

Stairway to SQL Server Replication: Level 3 - Transactional Replication – The Publisher

The Publisher is the database where all replicated data originates. Each Publisher can have multiple publications defined within it. Each publication contains a set of articles that all need to reside in a single database. Each article corresponds to all or part of a single database object. A single database object can map to an article in more than one publication.  Read more...

Stairway to SQL Server Replication: Level 4 - Transactional Replication – The Subscriber

The Subscriber is the server where all the changes that are published by replication get delivered to. Every publication needs to have at least one subscriber, but a publication can have many subscribers. This level assumes that you have followed the first three levels and that you have a publication set up, to which you can subscribe.  Read more...

Stairway to SQL Server Replication - Level 5: Transactional Replication & How it works

This level covers the details of SQL Server transactional and merge replication, from understanding the basic terminology and methodology of setting up replication, to describing how it works and how the basic replication processes can be monitored.   Read more...

Stairway to SQL Server Replication - Level 6: Merge Replication - Publication

This level covers the details of SQL Server transactional and merge replication, from understanding the basic terminology and methodology of setting up replication, to describing how it works and how the basic replication processes can be monitored.   Read more...

Stairway to SQL Server Replication - Level 7: Merge Replication – Subscription

This level of the Stairway will cover the details of SQL Server transactional and merge replication, from understanding the basic terminology and methodology of setting up replication, to describing how it works and how the basic replication processes can be monitored.   Read more...

Stairway to SQL Server Replication - Level 8: Merge Replication – How it works

How merge replication works, including the impact on the published database. The merge agent, different conflict situations and their resolutions are introduced.  Read more...

Stairway to SQL Server Replication - Level 9: The Replication Monitor

Introducing the replication monitor and how to use it to monitor replication health. It also introduces tracer tokens.  Read more...

Stairway to SQL Server Replication - Level 10: Troubleshooting

The final level of this Stairway takes you through how to identify and fix common errors.  Read more...

출처 : http://www.sqlservercentral.com/stairway/72401/ (SQL 관련된 자료가 많습니다.)

블로그 이미지

레몬도리 LemonDory

개발자의 이야기

--사용 방법 프로시저에 특정문자가 있는 프로시저를 찾고 싶을 때 사용

--조회 : 이름, 타입

DECLARE @p_SearchText nvarchar(MAX)

SET @p_SearchText = '*'

select t1.name,

  t1.type

from  sys.objects t1

where exists (

    select 'x'

    from syscomments t2

    where t1.object_id = t2.id

    and  t2.text like '%' + @p_SearchText + '%'

    )


출처 : http://cooldragon.tistory.com

블로그 이미지

레몬도리 LemonDory

개발자의 이야기


에러메시지

WMI공급자에 연결할 수 없습니다 . 권한이 없거나 서버에 연결할 수 없습니다. SQL Server 구성관리자에서는 SQL Server2005 서버만관리할 수 있습니다. 지정된 모듈을 찾을 수 없습니다 0x8007007e

Cannot connect to WMI provider. You do not have permission or the server is unreachable. Note that you can only manage SQL Server 2005 and later servers with SQL Server Configuration Manager.
The specified module could not be found. 0x8007007e

해결
블로그 이미지

레몬도리 LemonDory

개발자의 이야기

프로젝트에 Oracle이나 MSSql 프로시저로 한다는 말에 일단 Oracle을 설치해 보았다.

파일 다운로드는 http://www.oracle.com

다운 받고 압축을 풀면 아래와 같은 경로에 보면 Setup.exe 파일이 있다 
하지만 Windows 7이라면 잠시 Setup.exe를 실행시키고 싶은 욕구(?)를 참고 

\stage\prereq\db
\stage\prereq\db_prereqs\db
두 폴더에 있는 refhost.xml 를 메모장이나 기타 에디트 가능한 프로그램을 열어보자 
 ....생략....
  <CERTIFIED_SYSTEMS>
    <OPERATING_SYSTEM>
       <VERSION VALUE="5.0"/>
             ...생략...
    <!--Microsoft Windows Vista-->
    <OPERATING_SYSTEM>
      <VERSION VALUE="6.0"/>
    </OPERATING_SYSTEM>
  </CERTIFIED_SYSTEMS>
위와 같이 되어있을 것이다 
아래와 같이 변경하자 
  ....생략....
  <CERTIFIED_SYSTEMS>
    <OPERATING_SYSTEM>
       <VERSION VALUE="5.0"/>
             ...생략...
    <!--Microsoft Windows Vista-->
    <OPERATING_SYSTEM>
      <VERSION VALUE="6.0"/>
    </OPERATING_SYSTEM>
   <!--Microsoft Windows 7-->
    <OPERATING_SYSTEM>
      <VERSION VALUE="6.1"/>
    </OPERATING_SYSTEM>

  </CERTIFIED_SYSTEMS>
위 파란색 부분의 내용이 추가하면 된다.
두개 폴더 안의 파일을 모두 수정한다.

그렇게 하고 Setup.exe를 설치하느냐 
아직 한가지 더 남았다. 
Oracle Client에서는 설정해 줄 필요는 없었지만 Database 설치에선 한가지 더해줘야한다 

현재 상태에서도 설치를 진행한다면 네트워크 관련 오류가 뜰것이다.
(Oracle은 DHCP 할당 방식의 IP 주소를 사용하는 시스템에서의 설치를 지원합니다)

다음 컨트롤을 설치하고 진행해야 한다.
> Microsoft Lookback Adapter
설치 방법은 
실행창(Windows + R)에 hdwwiz.exe을 실행한다.
설정 과정은 이미지로 대신하겠다.
위 사진으로 진행한다면 이상없이 설치될 것이다.

마지막으로 네트워크 및 공유센터에서 왼쪽 메뉴 어댑터 설정 변경을 선택
속성으로 들어가 Internet protocol version IP4의 속성을 아래와 같이 변경한다.

이렇게 하면 네트워크 오류까지 잡게 된다.
이제 그 클릭질을 하고 싶어했던 Setup.exe파일을 실행하여 설치한다.
필자는 설치 과정중 oracle database configuration assistant 과정에서 몇가지 오류 메시지가 떳으나 무시해버렸다 
어떤 분은 재부팅 후에 설치하니 잘된다고 하는 분도 있었다.
참고하기 바란다.
블로그 이미지

레몬도리 LemonDory

개발자의 이야기