http://www.xappsoftware.com/wordpress/2014/10/30/install-mosquitto-on-mac-os-x/
https://www.jianshu.com/p/a356fd3340f3
2018年6月3日 星期日
CURL
curl -C - -L -v -O --retry 999 -S
"http://www.archive.org/download/usgs_drg_nc_35077_b1/o35077b1.tif"
CURL *curl; CURLcode res; struct curl_slist *headers=NULL; // init to NULL is important headers = curl_slist_append(headers, "Accept: application/json"); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/api/json/123");//cant get json file curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/pages/123.html");//this returns entire webpage curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_RETURNTRANSFER, true); res = curl_easy_perform(curl); if(CURLE_OK == res) { char *ct; // ask for the content-type res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct); if((CURLE_OK == res) && ct) printf("We received Content-Type: %s\n", ct); } } // always cleanup curl_easy_cleanup(curl);
"http://www.archive.org/download/usgs_drg_nc_35077_b1/o35077b1.tif"
CURL *curl; CURLcode res; struct curl_slist *headers=NULL; // init to NULL is important headers = curl_slist_append(headers, "Accept: application/json"); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/api/json/123");//cant get json file curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/pages/123.html");//this returns entire webpage curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_RETURNTRANSFER, true); res = curl_easy_perform(curl); if(CURLE_OK == res) { char *ct; // ask for the content-type res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct); if((CURLE_OK == res) && ct) printf("We received Content-Type: %s\n", ct); } } // always cleanup curl_easy_cleanup(curl);
PID
https://www.cyberciti.biz/faq/linux-pidof-command-examples-find-pid-of-program/
#!/bin/bash # please ignore our pid and get all pids of lighttpd on server list=$(pidof -o %PPID lighttpd) # .. now do something on all pids stored in $list for p in $list do echo "Killing $p..." kill -TERM $p done |
2018年6月1日 星期五
standard output
「>/dev/null 2>&1」實際上在這裡會將左邊程式的執行結果丟給「/dev/null」,然後不管程式有什麼錯誤,也會一併丟給 null。熟悉 Unix 的人大概知道,「/dev/null」是 Unix 底下的垃圾筒+黑洞。它不帶任何意義,所有丟進去的東西都會被吃掉然後不見,反正你不想看到的東西丟給 null 就對了。而「>」的意思其實是,將「>」左邊輸出的東西重新導向到右邊去。但不止是這樣而已,系統將標準輸入輸出分成三個:標準輸入 (stdin)、標準輸出 (stdout)、以及標準錯誤輸出 (stderr),它們的 fd (file descriptor, 檔案描述子) 分別是 0、1、2。當「>」左邊未指定任何東西時,它會讀取左方程式的標準輸出 (也就是 fd=1) 重新導向給右邊的東西,但是你也可以指定要重新導向的 fd (也就是說「>abc.txt」會等於「1>abc.txt」)。所以可以想見 2>&1 的意思應該是把 fd=2,也就是標準錯誤輸出重新導向給 &1。而這邊的 &1 指的其實就是 fd=1。這邊似乎有點混淆視聽的感覺,為什麼「>」前面的 fd 不需要指定 &,後面的 fd 卻又要加 & 呢?我沒找到確切的原因,但是根據這篇討論,我認為有可能是因為「>」左邊只接受 fd,但右邊所接收的語法卻應該是檔案名稱。因此若用「2>1」其結果會變成「將標準錯誤輸出重新導向給檔案名稱為 "1" 的檔案」,所以我們需要用 & 來告訴系統後面的 "1" 指的是 fd。
接下來,有趣的東西來了。根據「man bash」裡 REDIRECTION 段落裡的說明,重新導向的順序是由左至右。也就是說「>/dev/null 2>&1」會先處理「>/dev/null」再處理「2>&1」。如果聽到這裡你覺得怪的話,再告訴你一件很幹的事。用「2>&1 >/dev/null」並不會將 stderr 導到 /dev/null。「man bash」裡的說明如下:
接下來,有趣的東西來了。根據「man bash」裡 REDIRECTION 段落裡的說明,重新導向的順序是由左至右。也就是說「>/dev/null 2>&1」會先處理「>/dev/null」再處理「2>&1」。如果聽到這裡你覺得怪的話,再告訴你一件很幹的事。用「2>&1 >/dev/null」並不會將 stderr 導到 /dev/null。「man bash」裡的說明如下:
Note that the order of redirections is significant. For example, the
command
ls > dirlist 2>&1
directs both standard output and standard error to the file dirlist,
while the command
ls 2>&1 > dirlist
directs only the standard output to file dirlist, because the standard
error was duplicated as standard output before the standard output was
redirected to dirlist.
訂閱:
文章 (Atom)