{"id":3287,"date":"2021-07-06T06:18:14","date_gmt":"2021-07-05T21:18:14","guid":{"rendered":"http:\/\/matoken.org\/blog\/?p=3287"},"modified":"2021-07-06T06:18:16","modified_gmt":"2021-07-05T21:18:16","slug":"trouble-with-speedtest-cli-not-working-with-crontab","status":"publish","type":"post","link":"https:\/\/matoken.org\/blog\/2021\/07\/06\/trouble-with-speedtest-cli-not-working-with-crontab\/","title":{"rendered":"speedtest-cli \u304c crontab \u3067\u52d5\u4f5c\u3057\u306a\u304f\u3066\u56f0\u308b"},"content":{"rendered":"<div class=\"paragraph\">\n<p>\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u901f\u5ea6\u8a08\u6e2c\u30b5\u30a4\u30c8\u306eSpeedtest.net \u3068\u3044\u3046\u30b5\u30a4\u30c8\u304c\u3042\u308a\u307e\u3059\uff0e<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li><a href=\"https:\/\/www.speedtest.net\/\">Speedtest by Ookla &#8211; The Global Broadband Speed Test<\/a><\/li>\n<\/ul>\n<\/div>\n<div class=\"paragraph\">\n<p>\u4e16\u754c\u4e2d\u306b\u3042\u308b\u30b5\u30fc\u30d0\u306e\u3046\u3061\u81ea\u5206\u306e\u30a2\u30c9\u30ec\u30b9\u304b\u3089\u8fd1\u3044\u3067\u3042\u308d\u3046\u30b5\u30fc\u30d0\u3092\u9078\u3093\u3067\u901f\u5ea6\u8a08\u6e2c\u3092\u3057\u3066\u304f\u308c\u308b\u30b5\u30fc\u30d3\u30b9\u3067\u3059\uff0e<\/p>\n<\/div>\n<p><!--more--><\/p>\n<div class=\"paragraph\">\n<p>\u3053\u306e\u30b5\u30fc\u30d3\u30b9\u3092cli \u3067\u5b9f\u884c\u3067\u304d\u308bPython\u88fd speedtest-cli \u3068\u3044\u3046Apache 2.0\u30e9\u30a4\u30bb\u30f3\u30b9\u306e\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u306e\u30c4\u30fc\u30eb\u304c\u3042\u308a\u307e\u3059\uff0eDebian\u3060\u3068\u30d1\u30c3\u30b1\u30fc\u30b8\u3082\u3042\u308b\u306e\u3067\u5c0e\u5165\u3082\u7c21\u5358\u3067\u3059\uff0e<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li><a href=\"https:\/\/github.com\/sivel\/speedtest-cli\">sivel\/speedtest-cli: Command line interface for testing internet bandwidth using speedtest.net<\/a><\/li>\n<\/ul>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-shell\" data-lang=\"shell\">$ sudo apt install speedtest-cli\n$ speedtest-cli -h\nusage: speedtest-cli [-h] [--no-download] [--no-upload] [--single] [--bytes] [--share] [--simple] [--csv] [--csv-delimiter CSV_DELIMITER]\n                     [--csv-header] [--json] [--list] [--server SERVER] [--exclude EXCLUDE] [--mini MINI] [--source SOURCE] [--timeout TIMEOUT]\n                     [--secure] [--no-pre-allocate] [--version]\n\nCommand line interface for testing internet bandwidth using speedtest.net.\n-------------------------------------------------------------------------- https:\/\/github.com\/sivel\/speedtest-cli\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --no-download         Do not perform download test\n  --no-upload           Do not perform upload test\n  --single              Only use a single connection instead of multiple. This simulates a typical file transfer.\n  --bytes               Display values in bytes instead of bits. Does not affect the image generated by --share, nor output from --json or\n                        --csv\n  --share               Generate and provide a URL to the speedtest.net share results image, not displayed with --csv\n  --simple              Suppress verbose output, only show basic information\n  --csv                 Suppress verbose output, only show basic information in CSV format. Speeds listed in bit\/s and not affected by --bytes\n  --csv-delimiter CSV_DELIMITER\n                        Single character delimiter to use in CSV output. Default \",\"\n  --csv-header          Print CSV headers\n  --json                Suppress verbose output, only show basic information in JSON format. Speeds listed in bit\/s and not affected by --bytes\n  --list                Display a list of speedtest.net servers sorted by distance\n  --server SERVER       Specify a server ID to test against. Can be supplied multiple times\n  --exclude EXCLUDE     Exclude a server from selection. Can be supplied multiple times\n  --mini MINI           URL of the Speedtest Mini server\n  --source SOURCE       Source IP address to bind to\n  --timeout TIMEOUT     HTTP timeout in seconds. Default 10\n  --secure              Use HTTPS instead of HTTP when communicating with speedtest.net operated servers\n  --no-pre-allocate     Do not pre allocate upload data. Pre allocation is enabled by default to improve upload performance. To support systems\n                        with insufficient memory, use this option to avoid a MemoryError\n  --version             Show the version number and exit\nmatoken@t430s:\/media\/matoken\/rootfs\/home\/matoken\/Videos$<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>\u51fa\u529b\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\uff0ccsv\u3084json\u3067\u66f8\u304d\u51fa\u3059\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\uff0e<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre>$ speedtest-cli <b class=\"conum\">(1)<\/b>\nRetrieving speedtest.net configuration...\nTesting from freebit (203.0.113.0)...\nRetrieving speedtest.net server list...\nSelecting best server based on ping...\nHosted by OpenGW (Shizuoka) [64.23 km]: 82.301 ms\nTesting download speed................................................................................\nDownload: 1.51 Mbit\/s\nTesting upload speed......................................................................................................\nUpload: 0.95 Mbit\/s\n$ speedtest-cli --simple <b class=\"conum\">(2)<\/b>\nPing: 68.211 ms\nDownload: 8.11 Mbit\/s\nUpload: 0.84 Mbit\/s\n$ speedtest-cli --list | grep -i japan | grep -Ei 'kagoshima|miyazaki|kumamoto|ooita|fukuoka|saga|hitoyoshi' <b class=\"conum\">(3)<\/b>\n 8407) Allied Telesis Capital Corporation (Sagamihara, Japan) [175.03 km]\n35106) yoshis.jp (KDDI-NET) (Fukuoka, Japan) [687.23 km]\n38134) NousagiNetwork(@_0rze) (Fukuoka, Japan) [687.23 km]\n38947) Rikimoto (Fukuoka, Japan) [687.23 km]\n18709) extride inc (Hitoyoshi, Japan) [705.48 km]\n$ speedtest-cli --simple --server 18709 <b class=\"conum\">(4)<\/b>\nPing: 122.31 ms\nDownload: 6.01 Mbit\/s\nUpload: 0.81 Mbit\/s\n$ speedtest-cli --csv-header <b class=\"conum\">(5)<\/b>\nServer ID,Sponsor,Server Name,Timestamp,Distance,Ping,Download,Upload,Share,IP Address\n$ speedtest-cli --csv <b class=\"conum\">(6)<\/b>\n42842,Mamireimu Net Work's,Nara,2021-06-23T09:15:44.814808Z,177.32698372902544,86.096,8215354.331324884,1350756.2707027544,,203.0.113.0\n$ speedtest-cli --json | jq . <b class=\"conum\">(7)<\/b>\n{\n  \"download\": 7961762.454176666,\n  \"upload\": 1054738.8634894243,\n  \"ping\": 73.207,\n  \"server\": {\n    \"url\": \"http:\/\/speedtestooklaserverjapannagoyashizuoka.baobivawpvojawvianoipwqnpibvbqoubwuvbqasciboabowbcacacwcqcqx001.bar:8080\/speedtest\/upload.php\",\n    \"lat\": \"34.9756\",\n    \"lon\": \"138.3827\",\n    \"name\": \"Shizuoka\",\n    \"country\": \"Japan\",\n    \"cc\": \"JP\",\n    \"sponsor\": \"OpenGW\",\n    \"id\": \"42413\",\n    \"host\": \"speedtestooklaserverjapannagoyashizuoka.baobivawpvojawvianoipwqnpibvbqoubwuvbqasciboabowbcacacwcqcqx001.bar:8080\",\n    \"d\": 64.2282382602239,\n    \"latency\": 73.207\n  },\n  \"timestamp\": \"2021-06-23T09:19:28.880310Z\",\n  \"bytes_sent\": 1515520,\n  \"bytes_received\": 10101900,\n  \"share\": null,\n  \"client\": {\n    \"ip\": \"203.0.113.0\",\n    \"lat\": \"34.733\",\n    \"lon\": \"137.7439\",\n    \"isp\": \"freebit\",\n    \"isprating\": \"3.7\",\n    \"rating\": \"0\",\n    \"ispdlavg\": \"0\",\n    \"ispulavg\": \"0\",\n    \"loggedin\": \"0\",\n    \"country\": \"JP\"\n  }\n}<\/pre>\n<\/div>\n<\/div>\n<div class=\"colist arabic\">\n<ol>\n<li>\u65e2\u5b9a\u5024\u3067\u5b9f\u884c\u3059\u308b\u3068\u81ea\u5206\u306eip\u30a2\u30c9\u30ec\u30b9\u306egeoip\u3067\u8fd1\u3044\u30b5\u30fc\u30d0\u306bping\u3092\u6253\u3063\u3066\u8fd1\u305d\u3046\u306a\u30b5\u30fc\u30d0\u3092\u63a2\u3057\u3066\u901f\u5ea6\u30c6\u30b9\u30c8\u3059\u308b\uff0e(\u7269\u7406\u7684\u306b\u306f\u9e7f\u5150\u5cf6\u3060\u3051\u3069geoip\u3067\u306f\u9759\u5ca1\u6271\u3044\u306a\u306e\u3067\u305d\u306e\u5468\u308a\u304c\u4f7f\u308f\u308c\u308b)<\/li>\n<li>\u30b7\u30f3\u30d7\u30eb\u306a\u8868\u793a<\/li>\n<li>\u7269\u7406\u7684\u306b\u8fd1\u305d\u3046\u306a\u4e5d\u5dde\u5185\u306e\u30b5\u30fc\u30d0\u3092\u63a2\u3059<\/li>\n<li>\u7269\u7406\u7684\u306b\u4e00\u756a\u8fd1\u3044\u30b5\u30fc\u30d0\u3092\u6307\u5b9a<\/li>\n<li>csv\u30d8\u30c3\u30c0\u3092\u8868\u793a(\u8a08\u6e2c\u306f\u3057\u306a\u3044)<\/li>\n<li>csv\u5f62\u5f0f\u3067\u51fa\u529b<\/li>\n<li>json\u5f62\u5f0f\u3067\u51fa\u529b(\u3057\u3066 jq \u3067\u6574\u5f62)<\/li>\n<\/ol>\n<\/div>\n<div class=\"paragraph\">\n<p>\u3053\u308c\u3092crontab\u306b\u8a2d\u5b9a\u3057\u3066\u5b9a\u671f\u7684\u306b\u5b9f\u884c\u3057\uff0c\u901f\u5ea6\u306e\u5909\u5316\u3092\u898b\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3057\u305f\uff0e<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>crontab\u306b <code>*\/30 * * * *    speedtest-cli --csv &gt;&gt; ~\/log\/speedtest.csv<\/code> \u3092\u8a2d\u5b9a\u3057\u306630\u5206\u6bce\u306b\u901f\u5ea6\u30c6\u30b9\u30c8\u3092\u3057\u3066 <code>~\/log\/speedtest.csv<\/code> \u306b\u66f8\u304d\u51fa\u3057\u3066\u307f\u307e\u3059\uff0e<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">$ mkdir ~\/log <b class=\"conum\">(1)<\/b>\n$ speedtest-cli --csv-header &gt; ~\/log\/speedtest.csv <b class=\"conum\">(2)<\/b>\n$ crontab -e <b class=\"conum\">(3)<\/b>\n$ crontab -l | grep speedtest-cli <b class=\"conum\">(4)<\/b>\n*\/30 * * * *    speedtest-cli --csv &gt;&gt; ~\/log\/speedtest.csv<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"colist arabic\">\n<ol>\n<li>\u30ed\u30b0\u683c\u7d0d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4f5c\u6210<\/li>\n<li>csv\u30d8\u30c3\u30c0\u3092\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u307f<\/li>\n<li><code>crontab -e<\/code> \u3067\u4ee5\u4e0b\u306e\u884c\u3092\u8ffd\u52a0<\/li>\n<li>crontab\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u306e\u3092\u78ba\u8a8d<\/li>\n<\/ol>\n<\/div>\n<div class=\"paragraph\">\n<p>\u3057\u304b\u3057\uff0c\u624b\u52d5\u3067\u5b9f\u884c\u6642\u306b\u306f\u5931\u6557\u3057\u305f\u9803\u304c\u306a\u3044\u306e\u306bcrontab \u7d4c\u7531\u3060\u3068\u307b\u307c\u5168\u3066\u304c\u5931\u6557\u3057\u307e\u3059\uff0e\u307e\u308c\u306b\u6210\u529f\u3059\u308b\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u304c\uff0c10\u56de\u306b1\u56de\u3082\u6210\u529f\u3057\u307e\u305b\u3093\uff0e<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\uff0e<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre>ERROR: Unable to connect to servers to test latency.<\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>crontab\u3067\u3060\u3051\u30a8\u30e9\u30fc\u3068\u306a\u308b\u306e\u3067\uff0c\u30b3\u30de\u30f3\u30c9\u3092shell script file\u306b\u3057\u3066\u305d\u308c\u3092\u547c\u3076\u3088\u3046\u306b\u3057\u305f\u308a\uff0c\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u65b9\u6cd5\u3092\u5909\u66f4\u3057\u3066\u307f\u305f\u308a\uff0csource\u3092\u898b\u308b\u3068\u30b5\u30fc\u30d0\u30ea\u30b9\u30c8\u306e\u53d6\u5f97\u306b\u5931\u6557\u3057\u3066\u3044\u308b\u3088\u3046\u306a\u306e\u3067\u30b5\u30fc\u30d0\u3092\u6307\u5b9a\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u305f\u3051\u3069\u30b5\u30fc\u30d0\u3092\u6307\u5b9a\u3057\u3066\u3082\u30b5\u30fc\u30d0\u30ea\u30b9\u30c8\u3092\u53d6\u5f97\u3059\u308b\u306e\u3067\u610f\u5473\u304c\u306a\u304b\u3063\u305f\u308a\u3068\u3044\u3046\u3053\u3068\u3092\u8a66\u3057\u3066\u3044\u307e\u3057\u305f\uff0e<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>\u3082\u3057\u304b\u3057\u3066\u6bce0\u5206\uff0c30\u5206\u306e\u5b9f\u884c\u3059\u308b\u306e\u304c\u826f\u304f\u306a\u3044\u306e\u3067\u306f\u3068\uff0ccrontab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u30666\u5206\u306836\u5206\u306b\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u5909\u66f4\u305f\u3068\u3053\u308d\u308d\u52d5\u4f5c\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\uff0e<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-shell\" data-lang=\"shell\">$ crontab -l | grep speedtest-cli <b class=\"conum\">(1)<\/b>\n6,36 * * * *    speedtest-cli --csv &gt;&gt; ~\/log\/speedtest.csv<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>\u624b\u52d5\u3067\u30820\u5206\u4e01\u5ea6\u306b\u5b9f\u884c\u3059\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3057\u305f\uff0e<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre>$ speedtest-cli\nRetrieving speedtest.net configuration...\nTesting from freebit (180.131.110.140)...\nRetrieving speedtest.net server list...\nSelecting best server based on ping...\nERROR: Unable to connect to servers to test latency.<\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3068\u308a\u3042\u3048\u305a\u304d\u308a\u306e\u3044\u3044\u6642\u9593\u304b\u3089\u305a\u3089\u3059\u3068\u52d5\u304f\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\uff0e<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>\u5b9f\u306fSpeedTest\u516c\u5f0f\u306eCLI \u30c4\u30fc\u30eb\u3082\u3042\u308a\u3053\u308c\u3060\u3068\u4eca\u56de\u306e\u554f\u984c\u306f\u8d77\u3053\u3089\u306a\u3044\u3088\u3046\u3067\u3059\uff0e<br \/>\n\u30d0\u30a4\u30ca\u30ea\u3057\u304b\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u304c\uff0cmacOS\/Windows\/Linux\/FreeBSD\u7248\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u3066\uff0cLinux\u306fi386, x86_64, armlf, armhf, arm64 \u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\uff0e<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li><a href=\"https:\/\/www.speedtest.net\/apps\/cli\">Speedtest CLI &#8211; Internet connection measurement for developers<\/a><\/li>\n<\/ul>\n<\/div>\n<div class=\"paragraph\">\n<p>\u3053\u3061\u3089\u3092\u4f7f\u3046\u3068\u6bce0\u5206\uff0c30\u5206\u306b\u5b9f\u884c\u3057\u3066\u3082\u52d5\u4f5c\u3057\u307e\u3057\u305f\uff0e csv, tsv, json, jsonl, json-pretty` \u3067\u306e\u51fa\u529b\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u3057\u3053\u3061\u3089\u3092\u4f7f\u3046\u306e\u3082\u3042\u308a\u304b\u3082\u3057\u308c\u307e\u305b\u3093\uff0e\u305f\u3060source\u3082\u7121\u3044\u30572019\u5e74\u306e\u30ea\u30ea\u30fc\u30b9\u304b\u3089\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u4e0a\u304c\u3063\u3066\u3044\u306a\u3044\u306e\u3067\u30e1\u30f3\u30c6\u3055\u308c\u3066\u3044\u308b\u306e\u304b\u3061\u3087\u3063\u3068\u4e0d\u5b89\u3067\u3059\uff0e<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\">\u74b0\u5883<\/div>\n<div class=\"content\">\n<pre>$ dpkg-query -W speedtest-cli\nspeedtest-cli   2.1.3-2\n$ lsb_release -dr\nDescription:    Debian GNU\/Linux 11 (bullseye)\nRelease:        11\n$ arch\nx86_64<\/pre>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u901f\u5ea6\u8a08\u6e2c\u30b5\u30a4\u30c8\u306eSpeedtest.net \u3068\u3044\u3046\u30b5\u30a4\u30c8\u304c\u3042\u308a\u307e\u3059\uff0e Speedtest by Ookla &#8211; The Global Broadband Speed Test \u4e16\u754c\u4e2d\u306b\u3042\u308b\u30b5\u30fc\u30d0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"webmentions_disabled_pings":false,"webmentions_disabled":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[658,7,6,90],"tags":[399,253],"class_list":["post-3287","post","type-post","status-publish","format-standard","hentry","category-bullseye","category-debian-linux","category-linux","category-testing","tag-crontab","tag-speedtest"],"_links":{"self":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts\/3287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/comments?post=3287"}],"version-history":[{"count":0,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts\/3287\/revisions"}],"wp:attachment":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/media?parent=3287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/categories?post=3287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/tags?post=3287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}