- 投稿日:2020-07-05T23:37:14+09:00
【Mac】aliasの設定方法(再起動しても消えない)
- 投稿日:2020-07-05T11:48:16+09:00
【小ネタ】Ansibleでpingを飛ばせない場合の対処方法
はじめに
Mac上にbrewでAnsibleをインストールしました。(Ansible勉強中)
そこで、pingの実行に少々苦戦をしましたので、対処方法を載せたいと思います。事象
1つの対象にpingを実行すると、下記のようなエラーが表示される。
実行結果% ansible -i 192.168.56.51 all -m ping --connection=local [WARNING]: Unable to parse /Users/satton/etc/ansible/192.168.56.51 as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' %対処方法
IPアドレスの後に
,
を付ける。実行結果% ansible -i 192.168.56.51, all -m ping --connection=local [WARNING]: Platform darwin on host 192.168.56.51 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. 192.168.56.51 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } %
※複数ホストにpingを実行することも可能
実行結果% ansible -i 192.168.56.51,8.8.8.8,8.8.4.4 all -m ping --connection=local [WARNING]: Platform darwin on host 8.8.4.4 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. 8.8.4.4 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } [WARNING]: Platform darwin on host 192.168.56.51 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. 192.168.56.51 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } [WARNING]: Platform darwin on host 8.8.8.8 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. 8.8.8.8 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } %参考
- 投稿日:2020-07-05T10:36:50+09:00
Mac Javaホームディレクトリ
Macで、Javaのバージョンアップをする際に、毎回ホームディレクトリの場所を忘れてしまう。
.bashrc に記載している環境変数を見て、「そーだった」と納得しつつ、覚えられない自分がいる。
export JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home"ついでに brewでのJavaインストールコマンドも残しておきます。
brew tap AdoptOpenJDK/openjdk brew cask install adoptopenjdk14
- 投稿日:2020-07-05T00:29:48+09:00
[macOS]シェルスクリプトで簡易的なカウントダウンタイマーを作成する
概要
本書はシェルスクリプトを使用して簡易的なカウントダウンタイマーを作成します。
前提条件
- Macから音が出るようにボリュームを調整してください。
- 本書ではMacBookAir2019(macOS Catalina)を使用しました。
スクリプト内容
#!/bin/sh << COMMENTOUT countdown_timer(macOS) Copyright (c) 2020 yuichi1992_west This software is released under the MIT License. http://opensource.org/licenses/mit-license.php COMMENTOUT # A variable that checks whether only a numerical value (seconds) is entered using a regular expression. timer_count='[0-9]+' # Prompt for the time to play the sound (specify the number of seconds). echo "Prompt for the time to play the sound (specify the number of seconds)." echo "For example, enter [1] for 1 second, [60] for 1 minute, [3600] for 1 hour, and [86400] for 1 day." echo "After entering, press Enter. " read timer_seconds # Compare the entered value with the regular expression. if [[ $timer_seconds =~ $timer_count ]] ; then # If the regular expression is correct, start the countdown. echo "" echo "Start the countdown." # Increments by 1 with a for statement from 0 to the entered value. for ((i=0;i<$timer_seconds;i++)) do # Output the remaining time. echo "" echo "Remaining time (seconds)" expr $timer_seconds - $i echo "" # Wait 1 second. sleep 1 done # Sound the alarm (standard audio of macOS) 10 times. echo "It's time! Play the alarm!" for ((k=0;k<=10;k++)) do afplay /System/Library/Sounds/Ping.aiff done read -p "Press [Enter] key to resume." else # If the entered value is not a number, a warning will be prompted. echo "" echo "Important!! Characters other than numbers are included. Enter only half-width numbers from 0 to 9." echo "For example, enter [1] for 1 second, [60] for 1 minute, [3600] for 1 hour, and [86400] for 1 day." echo "" read -p "Press [Enter] key to resume." fi exit 0動作結果
成功の場合
% bash countdown_timer.sh Prompt for the time to play the sound (specify the number of seconds). For example, enter [1] for 1 second, [60] for 1 minute, [3600] for 1 hour, and [86400] for 1 day. After entering, press Enter. 5 Start the countdown. Remaining time (seconds) 5 Remaining time (seconds) 4 Remaining time (seconds) 3 Remaining time (seconds) 2 Remaining time (seconds) 1 It's time! Play the alarm! (システムで用意されている音声を10回鳴らします) Press [Enter] key to resume.
- 途中でアラームを止める場合は
control + C
を押してください。失敗の場合
% bash countdown_timer.sh Prompt for the time to play the sound (specify the number of seconds). For example, enter [1] for 1 second, [60] for 1 minute, [3600] for 1 hour, and [86400] for 1 day. After entering, press Enter. aaa Important!! Characters other than numbers are included. Enter only half-width numbers from 0 to 9. For example, enter [1] for 1 second, [60] for 1 minute, [3600] for 1 hour, and [86400] for 1 day. Press [Enter] key to resume.動作について
- 正規表現(数値のみ)の変数を宣言する。
timer_count='[0-9]+'
- 音声を鳴らす時間をユーザーに入力させる。
read timer_seconds
- 入力した値が全て数値(0-9)であるか判定する。
if [[ $timer_seconds =~ $timer_count ]] ;
- for文を利用してカウントダウンを始める。1秒ごとにiの値を1増やし、入力した時間になったらfor文から抜ける。
for ((i=0;i<$timer_seconds;i++))
- 残り時間(入力した時間 - iの値)を計算する。
expr $timer_seconds - $i
- 1秒待機する。
sleep 1
- iの値が入力した時間に達したら音声を10回鳴らす。
for ((k=0;k<=10;k++))
- システムで用意された音声を鳴らす。
afplay /System/Library/Sounds/Ping.aiff
- 10回鳴らした後、ユーザーにEnterキーを押させてスクリプトを終了する。
read -p "Press [Enter] key to resume."最後に
ターミナルを立ち上げて本書のシェルスクリプトを実行することでカウントダウンタイマーが利用できます。また
for ((k=0;k<=10;k++))
からkの値を変更してアラーム回数を増減させたり、afplay /System/Library/Sounds/Ping.aiff
から別のシステム音声や好きな曲に変更する、というカスタマイズもできます。