2019年3月21日 星期四
2019年3月14日 星期四
Bash Tip - Run Command with multiple arguments with ssh
This is a note for logging my simple way to use ssh and bash with continuous integration on remote server.
You can execute the following test-cases.sh on your host.
It will execute remote script of the test with correct argument contents.
source code of test-cases.sh on host
directory layout of tester account on test-server
source code of tests.sh on test-server
result of test-cases.sh example
source ./test-cases.sh
➜ ~ run_cases "\"1\"\"" "b'\"" "c'#\"" "\"\"" "\'"
ssh test-server cd test-cases; /bin/bash ./tests.sh "\"1\"\"" "b\'\"" "c\'\#\"" "\"\"" "\\'"
argv[1]=["1""]
argv[2]=[b\'"]
argv[3]=[c\'\#"]
argv[4]=[""]
argv[5]=[\\']
Notes
printf %q is use to make safe quote the argument if hashtag(#), quote('), double quote(") and so on.Appendix
2019年2月22日 星期五
Bash Tip - Use bash to implement like C's argc and argv
Test bash script capacity
I want to show how to write the advanced bash script with shift and array.
Feature:
Tested environments: - bash 4.3.48 x86_64-pc-linux-gnu ubuntu-16.04.4 LTS
I want to show how to write the advanced bash script with shift and array.
Feature:
- filter the arguments with '-' leading character as options
- the following inputs are the data arguments
Tested environments: - bash 4.3.48 x86_64-pc-linux-gnu ubuntu-16.04.4 LTS
2019年1月30日 星期三
DevOps Tip - How to use terraform apply without prompt and input yes for CI/CD?
Problem
Took a memo about integration of CI/CD applied by terraform without prompt to input 'yes'It is annoying to input yes every time if you already make sure already by `terraform plan`.
On the other hand, I need to integrate with different system for CI/CD. I need a way to approve it automatically.
By tests with commands official documents, I found the correct command and arguments.
Tested Solutions
terraform apply -input=false -auto-approve
or as my test, you can shorten to the following command
terraform apply -auto-approve
Test Environments
- Ubuntu 16.04.04 LTS
- OSX 10.14
Reference:
Extended Reading
2019年1月29日 星期二
DevOps Tip - How to use shared terraform plugins by -plugin-dir argument?
Problem
If you executed `terraform init`, you may already have the .terraform in your folder.
Because you may have many terraform repo similar to another, you can use the -plugin-dir to reduce the usage of disk space.
As a shared plugins so that we don’t need many copies of plugins into different locations.
Example
- Here I used my OSX Macbook as a Demo Environment.
====================
cd /build/setupdev/
sudo mkdir -p /opt/terraform/terraform.dcd /build/setupdev/
mv .terraform/plugins to /opt/terraform/terraform.d/plugins
- Please run the following command to apply it.
====================
-plugin-dir=/opt/terraform/terraform.d/plugins/darwin_amd64
Tree of .terraform
Tree of terraform plugins
Reference
2019年1月27日 星期日
OrangeOS's 作業系統實現範例出現微軟防毒Defender的誤偵測
年關將近,最近繼續在整理舊書,偶然間翻到了一本放了很久的舊書 OrangeOS's 一個作業系統的實現。
在Windows 10 系統中,想試試它的範例,發現 a.img 檔案複製不過來,覺得十分奇怪。
出現的路徑剛好是範例1的Hello World boot.asm 所對應的檔案 a.img
程式碼
/Dev/orangeos/chapter1/a$ make qemu-img create -f raw a.img 1440k Formatting 'a.img', fmt=raw size=1474560 mkfs.msdos -s 1 a.img mkfs.fat 3.0.28 (2015-05-16) nasm boot.asm -f bin -o boot.bin dd if=boot.bin of=./a.img bs=512 count=1 1+0 records in 1+0 records out 512 bytes copied, 0.000185582 s, 2.8 MB/s |
被偵測到有問題的boot.asm 範例
org 07c00h mov ax, cs mov ds, ax mov es, ax call DispStr jmp $ DispStr: mov ax, BootMessage mov bp, ax mov cx, 16 mov ax, 01301h mov bx, 000ch mov dl, 0 int 10h ret BootMessage: db "Hello, OS world!" times 510-($-$$) db 0 dw 0xaa55 |
通Defender 偵測的 boot.asm 範例
測試 ghaiklor 的 Simple boot sector with Hello World 範例編譯沒有問題source: https://gist.github.com/ghaiklor/89e243a3463569480d01188c9e55e077
執行編譯OK的Hello World
Windows 10 pro with qemu / make tools installed by choco
小結
比較程式的差異,通Defender 偵測的 boot.asm 範例,是比較好的寫法,有做處理停止中斷及結束。
看到偵測有病毒檔案訊息,先不用緊張,確認問題點,調整一下寫法,就可避開 Defender 誤偵測,繼續快樂的作業系統程式開發與研究囉!
看到偵測有病毒檔案訊息,先不用緊張,確認問題點,調整一下寫法,就可避開 Defender 誤偵測,繼續快樂的作業系統程式開發與研究囉!
延伸閱讀:
- Chocolatey是一個Windows下類似OSX brew 的軟體套件管理工具
- NASM - The Netwide Assembler 英文使用手冊
- 在Mac OS X上編繹BenOS並使用Qemu執行
- 讀"Orange's 一個作業系統的實現"的心得
2019年1月21日 星期一
如何在Mac上將微軟測試用虛擬機Image的zip 檔案解壓縮到特定目錄?
最近工作上,暫時會用到Windows 系統,
配合我的工作機所使用Parallels 虛擬化的軟體,
紀錄一下,在 MAC 上解壓縮微軟測試用虛擬機Image的zip 檔案到特定路徑並設定的方法
下載相關檔案:選擇你要使用的虛擬機版本,及對應的虛擬化平台。
➜ unzip IE11.Win7.Parallels.zip -d ~/vmspace/win7/
Archive: IE11.Win7.Parallels.zip
inflating: /Users/tester/vmspace/win7/.DS_Store
creating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/config.pvs
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/floppy.fdd
creating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/DiskDescriptor.xml
extracting: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/harddisk1.hdd
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/harddisk1.hdd.0.{5fbaabe3-6958-40ff-92a7-860e329aab41}.hds
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/harddisk1.hdd.drh
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/VmInfo.pvi
➜
配合我的工作機所使用Parallels 虛擬化的軟體,
紀錄一下,在 MAC 上解壓縮微軟測試用虛擬機Image的zip 檔案到特定路徑並設定的方法
Step 1: 從微軟網站上下載虛擬機
下載相關檔案:選擇你要使用的虛擬機版本,及對應的虛擬化平台。
Step 2: 開啟 Terminal Console (我使用的是 iTerm2.app)
Step 3: 確認 unzip 指令在 Mac OS X (10.14.2 ) 的使用方法
在 terminal console 中輸入 man unzip, 可得知參數 -d exdirStep 4: 解壓縮
以微軟30天測試用 Windows 7 Enterprise 虛擬機器 Parallels 檔案為例:➜ unzip IE11.Win7.Parallels.zip -d ~/vmspace/win7/
Archive: IE11.Win7.Parallels.zip
inflating: /Users/tester/vmspace/win7/.DS_Store
creating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/config.pvs
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/floppy.fdd
creating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/DiskDescriptor.xml
extracting: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/harddisk1.hdd
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/harddisk1.hdd.0.{5fbaabe3-6958-40ff-92a7-860e329aab41}.hds
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/harddisk1.hdd/harddisk1.hdd.drh
inflating: /Users/tester/vmspace/win7/IE11 - Win7.pvm/VmInfo.pvi
➜
Step 5: 執行 pvm
即可在 /Users/tester/vmspace/win7 中找到 IE11 - Win7.pvm,點擊 pvm 檔案執行Step 6: 執行後會看到對應的 IE11-Win7 的虛擬桌面
Step 7:安裝 Parallels Tools
用以安裝虛擬機平台相關驅動程式及擴充功能,安裝完成後,虛擬機需要重新啟動。
Step 8: 開始使用測試虛擬機
請注意:虛擬機預設定密碼為 Passw0rd!
小結
虛擬化平台對於軟體在不同系統開發測試是必要工具,可減少重覆安裝系統的時間,搭配CI (持續整合),更能加速開發進度喔!
訂閱:
文章 (Atom)










