윈도우 서버용 일일점검 배치 스크립트를 짜던중 막히는 부분이 있어 문의 드립니다.
일단 "OS 정보"와 "메모리 갯수"에 대한 정보를 텍스트 파일로 저장하는 스크립트 입니다.
명령어는 2가지를 사용했습니다.
1. wmic os get Caption, CSDVersion, Version >> C:\SECURITY\Result.txt
2. wmic memorychip get BankLabel >> C:\SECURITY\Result.txt
위 명령어를 기반으로 스크립트를 작성했는데 내용은 아래와 같습니다.
@echo off
set YEAR=%date:~0,4%
set MONTH=%date:~5,2%
set DAY=%date:~8,2%
set HOUR=%time:~0,2%
set MIN=%time:~3,2%
set DATETIME=%YEAR%%MONTH%%DAY%_%HOUR%%MIN%
echo *************************************************************************** >> C:\%datetime%.txt
echo 1.1. OS Informatiom >> C:\%datetime%.txt
echo *************************************************************************** >> C:\%datetime%.txt
wmic os get Caption, CSDVersion, Version >> C:\%datetime%.txt
echo.>> C:\%datetime%.txt
set YEAR=%date:~0,4%
set MONTH=%date:~5,2%
set DAY=%date:~8,2%
set HOUR=%time:~0,2%
set MIN=%time:~3,2%
set DATETIME=%YEAR%%MONTH%%DAY%_%HOUR%%MIN%
echo *************************************************************************** >> C:\%datetime%.txt
echo 1.1. OS Informatiom >> C:\%datetime%.txt
echo *************************************************************************** >> C:\%datetime%.txt
wmic os get Caption, CSDVersion, Version >> C:\%datetime%.txt
echo.>> C:\%datetime%.txt
echo *************************************************************************** >> C:\%datetime%.txt
echo 1.2. Memorychip Information >> C:\%datetime%.txt
echo *************************************************************************** >> C:\%datetime%.txt
wmic memorychip get BankLabel >> C:\%datetime%.txt
for /f "tokens=2 delims==" %%a in ('wmic MEMORYCHIP get BankLabel /format:list') do set BankLabel=%%a
echo %BankLabel% >> C:\%datetime%.txt
echo.>> C:\%datetime%.txt
echo 1.2. Memorychip Information >> C:\%datetime%.txt
echo *************************************************************************** >> C:\%datetime%.txt
wmic memorychip get BankLabel >> C:\%datetime%.txt
for /f "tokens=2 delims==" %%a in ('wmic MEMORYCHIP get BankLabel /format:list') do set BankLabel=%%a
echo %BankLabel% >> C:\%datetime%.txt
echo.>> C:\%datetime%.txt
그런데 위 스크립트 내용을 배치파일(*.bat)작성해서 돌려보내 결과파일(*.txt)에 "nul" 이 삽입되어 결과가 저장되는데...
결과에서 nul 을 제거해여 저장할려면 어떻게 해야 할까요?
구글을 뒤져보다가 지쳐서 질문 올립니다.
아시는분 도움 부탁 드립니다...ㅠ.ㅜ;;
¹Ù²Ü´Ü¾îºÎºÐÀÌ ºñ¾îÀÖÀ¸¸é Áö¿ì´Â°Å±¸¿ä, ƯÁ¤¹®ÀÚ¸¦ ³ÖÀ¸¸é ġȯµÇ´Â°Ì´Ï´Ù.
http://withserver.tistory.com/entry/notepad-%EC%97%90%EC%84%9C-%EB%B9%88%EC%A4%84%EC%A0%9C%EA%B1%B0-%EB%B0%8F-%EA%B3%B5%EB%B0%B1%EC%A1%B0%EC%A0%88%EC%A0%9C%EA%B1%B0%EB%B0%A9%EB%B2%95
µµ½º¿¡¼´Â Á» ¾î·Æ°í, ¼¹ö¶ó´Ï ÆÄ¿ö½©¿¡¼ °¡´ÉÇѵíÇÕ´Ï´Ù.
https://social.technet.microsoft.com/Forums/sharepoint/en-US/1df1ae68-4425-438f-8f0c-727ad70a1576/replacing-null-characters-in-file?forum=winserverpowershell
¾Æ´Ï¸é cygwin ±ò¾Æ¼ sed·Î ġȯÇصµ ÁÁ½À´Ï´Ù.
@echo off
set YEAR=%date:~0,4%
set MONTH=%date:~5,2%
set DAY=%date:~8,2%
set HOUR=%time:~0,2%
set MIN=%time:~3,2%
set DATETIME=%YEAR%%MONTH%%DAY%_%HOUR%%MIN%
echo *************************************************************************** >> C:\SECURITY\%datetime%.txt
echo 1.1. OS Informatiom >> C:\SECURITY\%datetime%.txt
echo *************************************************************************** >> C:\SECURITY\%datetime%.txt
wmic /output:z.txt os get Caption, CSDVersion, Version >> C:\SECURITY\%datetime%.txt
type z.txt >> C:\SECURITY\%datetime%.txt
echo.>> C:\SECURITY\%datetime%.txt
echo *************************************************************************** >> C:\SECURITY\%datetime%.txt
echo 3.2. Memorychip Information >> C:\SECURITY\%datetime%.txt
echo *************************************************************************** >> C:\SECURITY\%datetime%.txt
wmic /output:z.txt memorychip get BankLabel >> C:\SECURITY\%datetime%.txt
type z.txt >> C:\SECURITY\%datetime%.txt
for /f "tokens=2 delims==" %%a in ('wmic MEMORYCHIP get BankLabel /format:list') do set BankLabel=%%a
echo %BankLabel% >> C:\SECURITY\%datetime%.txt
echo.>> C:\SECURITY\%datetime%.txt
pause
http://stackoverflow.com/questions/10210553/cmd-is-somehow-writing-chinese-text-as-output
ÀÏ´Ü À§ ¸µÅ©±¸¿ä.. ù¹ø° ´äº¯ ¸»°í µÎ¹ø° ´äº¯¿¡ A¿Í B µÎ °¡Áö ¹æ¹ýÀÌ Á¦½ÃµÇ¾î Àִµ¥, ±× Áß B°¡ À§ Ź«Áø´Ôó·³ º°µµÀÇ ÀÓ½ÃÆÄÀÏ·Î ÀÏ´Ü ¹Þ°í ±×°É ´Ù½Ã type Çؼ ÃÖÁ¾ °á°ú ÆÄÀÏ¿¡ µ¡ºÙÀÌ´Â ½ÄÀÔ´Ï´Ù.
±Ùº»ÀûÀÎ ¿øÀÎÀº, ±âº»ÀûÀ¸·Î ¸í·Éâ¿¡¼ÀÇ Ãâ·ÂÀº ANSIÀε¥ WMICÀÇ Ãâ·ÂÀÌ ¸®´ÙÀÌ·ºÆ®µÉ ¶§ À¯´ÏÄÚµå·Î Ãâ·ÂÀÌ µÈ´Ù´Â °Å.. ±×·¡¼ ÃÖÃÊ echo·Î Ãâ·ÂµÈ ¹®ÀÚµéÀÌ ANSIÄÚµåÀε¥ WMICÀÇ ¸®´ÙÀÌ·ºÆ®µÈ Ãâ·ÂÀÌ À¯´ÏÄÚµå·Î µé¾î¿À´Ï ÇϳªÀÇ ÆÄÀÏ ¾È¿¡¼ Äڵ尡 ¼¯¿©¼ ±×·¸°Ô µÇ´Â °Å³×¿ä.
ÇÑÆí, A¹æ¹ýÀº ¾ÖÃÊ¿¡ ¸í·Éâ ÀÚü¸¦ À¯´ÏÄÚµå·Î ¶ç¿ö¼, WMIC ¿ÜÀÇ ´Ù¸¥ Ãâ·Âµµ ÀüºÎ À¯´ÏÄÚµå·Î Çعö¸®´Â ¹æ¹ýÀ̳׿ä. ¤¾¤¾ Áï, ÆÄÀÏ ÀÚü°¡ óÀ½ºÎÅÍ À¯´ÏÄÚµå·Î »ý¼ºµÇ¹Ç·Î Å©±â´Â Ä¿ÁöÁö¸¸, ÀÏ´Ü Äڵ尡 ÅëÀϵǾî ÀÖÀ¸´Ï º¸´Âµ¥´Â ¹®Á¦°¡ ¾ø´Ù´Â °ÅÁÒ. (¹ÙÀ̳ʸ® ¿¡µðÅÍ·Î º¸¸é °¢ ¹®ÀÚ°¡ 2¹ÙÀÌÆ®¾¿ ÀâÇô ÀÖ´Â °Ô º¸ÀÌ°ÚÁö¸¸¿ä. ¤¾¤¾)
Ź«Áø´Ô²²¼ ÈòÆ®¸¦ Áּż ÀÓ½ÃÆÄÀÏÀ» »ý¼ºÇÑ ÈÄ typeÀ» ÀÌ¿ëÇØ ÀÓ½ÃÆÄÀÏ ³»¿ëÀ» °á°úÆÄÀÏ¿¡ µ¡ºÙÀÌ´Â ½ÄÀ¸·Î ¹®Á¦¸¦ ÇØ°áÇÏ¿´½À´Ï´Ù.
´Ù½ÃÇѹø °¨»çÀÇ ¸»¾¸µå¸³´Ï´Ù.^^