<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>curl &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/curl/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Sun, 12 Mar 2023 13:05:04 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>curl &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>curl 的詭異問題 &#8211; Vultr DNS 設定</title>
		<link>https://noter.tw/115/curl-%e7%9a%84%e8%a9%ad%e7%95%b0%e5%95%8f%e9%a1%8c-vultr-dns-%e8%a8%ad%e5%ae%9a/</link>
					<comments>https://noter.tw/115/curl-%e7%9a%84%e8%a9%ad%e7%95%b0%e5%95%8f%e9%a1%8c-vultr-dns-%e8%a8%ad%e5%ae%9a/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sun, 16 Sep 2018 14:51:03 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Vultr]]></category>
		<category><![CDATA[resolv.conf]]></category>
		<category><![CDATA[nameserver]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=115</guid>

					<description><![CDATA[<p>之前朋友買了一台 Vultr 的主機，據說是蠻穩定的，而且重點是日本的機房 ping 大約只有 50ms 左右，一切聽起來都比小蛙用的遠在 LA，ping 隨便都 150ms 起跳來的強，但是價位也相&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/115/curl-%e7%9a%84%e8%a9%ad%e7%95%b0%e5%95%8f%e9%a1%8c-vultr-dns-%e8%a8%ad%e5%ae%9a/" data-wpel-link="internal">curl 的詭異問題 &#8211; Vultr DNS 設定</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>之前朋友買了一台 <a rel="noreferrer noopener nofollow external" href="https://www.vultr.com/" target="_blank" data-wpel-link="external" class="wpel-icon-right">Vultr<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 的主機，據說是蠻穩定的，而且重點是日本的機房 ping 大約只有 50ms 左右，一切聽起來都比小蛙用的遠在 LA，ping 隨便都 150ms 起跳來的強，但是價位也相對偏高，今天遇到了一個奇怪的狀況，這邊記錄一下解決方法。 </p>



<span id="more-115"></span>



<p>今天接到朋友的求助，php curl 貌似有問題，朋友自己也不確定問題在哪裡，只知道 API 放在遠振一切正常，但是移到 vultr 就有問題，大約幾十個 request 會遇到一個等待到 timeout 的情況，當時小蛙人在外面，大概聽了問題，還不清楚確切的原因，因為 php curl 的對象是自己 &#8230; 是自己還會等到 timeout？</p>



<p>一開始看 code，釐清所有的功能之後，感覺上沒有什麼問題，於是想說在 command line 直接下 curl 看看狀況，雖然不一定會跟 php 下 curl 完全一樣的情況，但至少試試看不吃虧 ~ 下了 curl -v https://xxxxxxxxx 後，詭異的事情來了，竟然等了很久都沒反應，甚至有時候還會出現 timeout 或是名稱無法解析的問題，連 ping 自己的 hostname 都 ping 不到，這是什麼好笑的狀況 &#8230;</p>



<p>後來小蛙在 /etc/hosts 上加入了 domain 對應之後，curl 自己的 API 至少沒問題了，看起來可以大聲說打完收工了。不久之後，小蛙又接到朋友電話，說有某個 domain curl 等到 timeout，該 domain 是外部的，有了上面的經驗後，小蛙第一次時間就 ping 該 domain，喔買尬 &#8230; 名稱無法解析，那試試看 ping noter.tw，ㄜ ~ 名稱無法解析，看來是 DNS 的問題了！</p>



<h2 class="para wp-block-heading">設定 Nameserver</h2>



<p>上網查了一下 ubuntu 的 DNS 設定編輯 ，使用 Google 的 8.8.8.8 跟 8.8.4.4 就好了，換上之後一切正常。 </p>



<p>小蛙在查資料的過程中看到有些人問，每次重開機之後這個設定檔都會恢復預設值該怎麼辦，其他人提出的解法感覺很複雜，小蛙也懶得測試，於是跟朋友要了 vultr 的帳密，也許可以直接透過網站直接設定就好，切換到 Network 設定部份，果然找到設定的方法：</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://noter.tw/wp-content/uploads/2018/09/1537109032408.jpg" alt="1537109032408 curl 的詭異問題 - Vultr DNS 設定" class="wp-image-4078" title="curl 的詭異問題 - Vultr DNS 設定"></figure></div>



<h2 class="para wp-block-heading">開機後額外調整 resolv.conf 內容</h2>



<p>小蛙設定上去後 reboot，花惹發 &#8230; 又跑回原本的設定 108.61.10.10，嗯 ~ 只好使出比較下三濫的手法了，修改 .bashrc，可能有更正統或正規的作法，但 &#8230; 趕時間，又剛好想到這個方法，就 ~ 先這樣子吧！常常聽到 sed 跟 awk 是神兵級的，但小蛙一直不知道怎麼用，通常都是想到什麼功能好像有，去查一下正確用法來套，於是找到&nbsp;<a rel="noreferrer noopener nofollow external" href="https://www.phpini.com/linux/sed-delete-file-whole-line" target="_blank" data-wpel-link="external" class="wpel-icon-right">sed 搜尋並刪除整行資料<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 這篇，設定完重開機，就可以看到效果了！</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">vim .bashrc 
sed -i '/108.61.10.10/d' /etc/resolv.conf </pre>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/115/curl-%e7%9a%84%e8%a9%ad%e7%95%b0%e5%95%8f%e9%a1%8c-vultr-dns-%e8%a8%ad%e5%ae%9a/" data-wpel-link="internal">curl 的詭異問題 &#8211; Vultr DNS 設定</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/115/curl-%e7%9a%84%e8%a9%ad%e7%95%b0%e5%95%8f%e9%a1%8c-vultr-dns-%e8%a8%ad%e5%ae%9a/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ubuntu 16.04 curl: Server Certificate Verification Failed.</title>
		<link>https://noter.tw/281/ubuntu-16-04-curl-server-certificate-verification-failed/</link>
					<comments>https://noter.tw/281/ubuntu-16-04-curl-server-certificate-verification-failed/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Mon, 25 Jun 2018 05:28:16 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[https]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=281</guid>

					<description><![CDATA[<p>今天看到有使用者留言說，我的股票精算師的指數不會更新了，小蛙檢查了一下，哇賽～從 5/16 開始就不會動了，立馬看看出了什麼問題。 一開始以為是之前搬伺服器的時候，Cloudflare 設定的問題，查&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/281/ubuntu-16-04-curl-server-certificate-verification-failed/" data-wpel-link="internal">Ubuntu 16.04 curl: Server Certificate Verification Failed.</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[<p>今天看到有使用者留言說，我的股票精算師的指數不會更新了，小蛙檢查了一下，哇賽～從 5/16 開始就不會動了，立馬看看出了什麼問題。</p>
<p><span id="more-281"></span></p>
<p>一開始以為是之前搬伺服器的時候，Cloudflare 設定的問題，查了一段時間後發現連搜尋股票代號的功能都失效了，進資料庫看一下股票代號表，發現空白一片，此時大概知道問題出在哪裡。</p>
<p>把 crontab 裡更新股票代碼跟指數的 API 叫出來看一下發現「curl: server certificate verification failed.」這個錯誤，仔細看一下錯誤訊息裡面其實就有解決方法了，不過小蛙還是記錄一下備查。</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-4008" src="https://noter.tw/wp-content/uploads/2018/06/curlssl-1024x268.png" alt="curlssl Ubuntu 16.04 curl: Server Certificate Verification Failed." width="800" height="209" title="Ubuntu 16.04 curl: Server Certificate Verification Failed."></p>
<pre class="EnlighterJSRAW" data-enlighter-language="bash">curl: (60) server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.</pre>
<p>有看到亮點了嗎？原本是 curl https://wxxxxxxx 改成 curl -k https://wxxxxxx 就可以忽略掉這個問題，但是同時也要注意存取目的的安全性喔！</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/281/ubuntu-16-04-curl-server-certificate-verification-failed/" data-wpel-link="internal">Ubuntu 16.04 curl: Server Certificate Verification Failed.</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/281/ubuntu-16-04-curl-server-certificate-verification-failed/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>crontab -e相關使用及問題</title>
		<link>https://noter.tw/2000/crontab-e%e7%9b%b8%e9%97%9c%e4%bd%bf%e7%94%a8%e5%8f%8a%e5%95%8f%e9%a1%8c/</link>
					<comments>https://noter.tw/2000/crontab-e%e7%9b%b8%e9%97%9c%e4%bd%bf%e7%94%a8%e5%8f%8a%e5%95%8f%e9%a1%8c/#comments</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Wed, 15 Feb 2012 13:39:13 +0000</pubDate>
				<category><![CDATA[網頁後端]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[crontab]]></category>
		<guid isPermaLink="false">http://wazai.net/?p=2000</guid>

					<description><![CDATA[<p>(2012-02-18更新)小蛙打算在「我的股票精算師」中加入可以即時查詢大盤以及個股的資訊，再透過RESTful的方式讓手機取得，而Server從證交所取得資料的部分，可能設定每分鐘或每五分鐘更新一&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/2000/crontab-e%e7%9b%b8%e9%97%9c%e4%bd%bf%e7%94%a8%e5%8f%8a%e5%95%8f%e9%a1%8c/" data-wpel-link="internal">crontab -e相關使用及問題</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[<p>(2012-02-18更新)小蛙打算在「<span style="color: #ff0000;"><strong>我的股票精算師</strong></span>」中加入可以<strong>即時查詢大盤以及個股</strong>的資訊，再透過<strong><span style="color: #ff0000;">RESTful</span></strong>的方式讓手機取得，而Server從證交所取得資料的部分，可能設定每分鐘或每五分鐘更新一次(降低Request次數，不曉得太頻繁的Request會不會被ban掉)，定期執行某項工作的任務就交給超好用的<span style="color: #ff0000;"><strong>crontab</strong></span>，這篇文章小蛙要記錄<strong>crontab -e設定以及執行PHP程式</strong>。<br />
<span id="more-2000"></span><br />
Linux部份的東西小蛙是一點兒也不拿手，下面的資料也都是從Google找到的，小蛙在<strong><a href="http://www.hkcode.com/programming/414" target="_blank" rel="noopener noreferrer nofollow external" data-wpel-link="external" class="wpel-icon-right">讓 crontab 自動排程執行 php @ 網路技術日誌<span class="wpel-icon wpel-image wpel-icon-6"></span></a></strong>中找到讓crontab執行php的方法，小蛙使用了文章中的方法二，直接從crontab -e去設定要執行的路徑及方法，做法如下：</p>
<pre class="brush: text; gutter: false">*/5  *  *  *    1-6     /usr/lib/cgi-bin/php5 -q /xxx/ooo/111.php &gt;&gt; /root/php 2&gt;&amp;2</pre>
<p>第一個<span style="color: #ff0000;"><span style="color: #000000;">「</span><strong>*/5</strong><span style="color: #000000;">」</span></span>指的是<span style="color: #000000;"><strong>每5分鐘執行一次</strong></span>(詳細設定請參考<strong><a href="https://linux.vbird.org/linux_basic/centos7/0430cron.php" target="_blank" rel="noopener noreferrer nofollow external" data-wpel-link="external" class="wpel-icon-right">第十六章、例行性工作排程 (crontab) @ 鳥哥的Linux私房菜<span class="wpel-icon wpel-image wpel-icon-6"></span></a></strong>)，「<strong><span style="color: #ff0000;">1-6</span></strong>」指的是<strong><span style="color: #000000;">星期一到星期六</span></strong>都要。「<span style="color: #ff0000;"><strong>/usr/lib/cgi-bin/php5 -q</strong></span>」小蛙不曉得為什麼PHP路徑在那麼奇怪的地方，後面的<span style="color: #ff0000;"><strong>-q</strong></span>也懶得去查所代表的意義，總之可以跑就對了(太懶&gt;&lt;)，「<span style="color: #ff0000;"><strong>/xxx/ooo/111.php</strong></span>」是要執行的PHP路徑。<br />
設定好之後確實是可以正常運作了，但是後來發現如果別人也知道這個網址，只要在瀏覽器打上一樣的網址，程式就會運行一次 &#8230; 聽起來是多麼可怕的一件事，所以小蛙加上了現在大家最常用的API KEY的方式判斷是否為「<strong>有權限執行</strong>」。但是上面的方法似乎就不能夠帶參數了，<strong><a href="http://www.piaoyi.org/php/Cron-PHP-parameter.html" target="_blank" rel="noopener noreferrer nofollow external" data-wpel-link="external" class="wpel-icon-right">Cron定时执行带参数的PHP代码 @ 飘易博客<span class="wpel-icon wpel-image wpel-icon-6"></span></a></strong>中提到了三種可以帶參數定期執行PHP的方法，恰巧小蛙前陣子在試node.js的時候已經安裝了<span style="color: #ff0000;"><strong>curl</strong></span>(不知道什麼是curl以及如何安裝，請到<strong><a href="http://tavi.debian.org.tw/index.php?page=curl" target="_blank" rel="noopener noreferrer nofollow external" data-wpel-link="external" class="wpel-icon-right">curl @ DebianWiki<span class="wpel-icon wpel-image wpel-icon-6"></span></a></strong>)，就決定用第三種(看起來也比較簡單)。</p>
<pre class="brush: text; gutter: false">*/5 * * * 1-6 curl 'http://xxx/ooo/111.php?APIKEY=123456&amp;s=hi' &gt;&gt; /root/php 2&gt;&amp;2</pre>
<p>上面那行就是最後的結果囉！希望這篇文章能對像小蛙一樣跟Linux不熟的網友有幫助！<br />
2012-02-18<br />
之前寫的定期備份wordpress的shell script手動可以正常執行，但只要放進crontab就完全不會動 &#8230; 後來在<strong><a href="https://linux.vbird.org/linux_basic/" target="_blank" rel="noopener noreferrer nofollow external" data-wpel-link="external" class="wpel-icon-right">鳥哥的 Linux 私房菜<span class="wpel-icon wpel-image wpel-icon-6"></span></a></strong>中發現shell script第一行要宣告使用的shell名稱。</p>
<blockquote><p>第一行 #!/bin/bash 在宣告這個 script 使用的 shell 名稱：<br />
因為我們使用的是 bash ，所以，必須要以『 <strong>#!/bin/bash</strong> 』來宣告這個檔案內的語法使用 bash 的語法！那麼當這個程式被執行時，他就能夠載入 bash 的相關環境設定檔 (一般來說就是 non-login shell 的 ~/.bashrc)， 並且執行 bash 來使我們底下的指令能夠執行！這很重要的！(在很多狀況中，如果沒有設定好這一行， 那麼該程式很可能會無法執行，因為系統可能無法判斷該程式需要使用什麼 shell 來執行啊！)</p></blockquote>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/2000/crontab-e%e7%9b%b8%e9%97%9c%e4%bd%bf%e7%94%a8%e5%8f%8a%e5%95%8f%e9%a1%8c/" data-wpel-link="internal">crontab -e相關使用及問題</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/2000/crontab-e%e7%9b%b8%e9%97%9c%e4%bd%bf%e7%94%a8%e5%8f%8a%e5%95%8f%e9%a1%8c/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
