Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2019-12-05 20:42:56 +08:00
commit 0cce368a10
12 changed files with 839 additions and 85 deletions

View File

@ -1,8 +1,8 @@
[#]: collector: "lujun9972"
[#]: translator: "lxbwolf"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-11645-1.html"
[#]: subject: "Bash Script to View System Information on Linux Every Time You Log into Shell"
[#]: via: "https://www.2daygeek.com/bash-shell-script-view-linux-system-information/"
[#]: author: "Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/"
@ -10,11 +10,7 @@
Bash 脚本实现每次登录到 Shell 时可以查看 Linux 系统信息
======
Linux 中有很多可以查看系统信息如处理器信息,生产商名字,序列号等的命令。
你可能需要执行多个命令来收集这些信息。
同时,记住所有的命令和他们的选项也是有难度。
Linux 中有很多可以查看系统信息如处理器信息、生产商名字、序列号等的命令。你可能需要执行多个命令来收集这些信息。同时,记住所有的命令和他们的选项也是有难度。
你可以写一个 [shell 脚本](https://www.2daygeek.com/category/shell-script/) 基于你的需求来自定义显示的信息。
@ -24,14 +20,12 @@ Linux 中有很多可以查看系统信息如处理器信息,生产商名字
这个j脚本有 6 部分,细节如下:
* **Part-1:** 通用系统信息
* **Part-2:** CPU/内存当前使用情况
* **Part-3:** 硬盘使用率超过 80%
* **Part-4:** 列出系统 WWN 详情
* **Part-5:** Oracle DB 实例
* **Part-6:** 可更新的包
1. 通用系统信息
2. CPU/内存当前使用情况
3. 硬盘使用率超过 80%
4. 列出系统 WWN 详情
5. Oracle DB 实例
6. 可更新的包
我们已经基于我们的需求把可能需要到的信息加到了每个部分。之后你可以基于自己的意愿修改这个脚本。
@ -39,21 +33,19 @@ Linux 中有很多可以查看系统信息如处理器信息,生产商名字
你可以参照以前文章,了解工具详情。
* **[inxi A Great Tool to Check Hardware Information on Linux][3]**
* **[Dmidecode Easy Way To Get Linux System Hardware Information][3]**
* **[LSHW (Hardware Lister) A Nifty Tool To Get A Hardware Information On Linux][3]**
* **[hwinfo (Hardware Info) A Nifty Tool To Detect System Hardware Information On Linux][3]**
* **[python-hwinfo : Display Summary Of Hardware Information Using Standard Linux Utilities][3]**
* **[How To Use lspci, lsscsi, lsusb, And lsblk To Get Linux System Devices Information][3]**
* **[How To Check System Hardware Manufacturer, Model And Serial Number In Linux][3]**
* **[How To Find WWN, WWNN and WWPN Number Of HBA Card In Linux][3]**
* **[How to check HP iLO Firmware version from Linux command line][3]**
* **[How to check Wireless network card and WiFi information from Linux Command Line][3]**
* **[How to check CPU & Hard Disk temperature on Linux][3]**
* **[Hegemon A modular System & Hardware monitoring tool for Linux][3]**
* **[How to Check System Configuration and Hardware Information on Linux][3]**
* [inxi 在 Linux 上检查硬件信息的绝佳工具][3]
* [Dmidecode 获取 Linux 系统硬件信息的简便方法][4]
* [LSHW硬件列表程序 在 Linux 上获取硬件信息的漂亮工具][5]
* [hwinfo硬件信息 在 Linux 上检测系统硬件信息的漂亮工具][6]
* [python-hwinfo使用标准 Linux 实用工具显示硬件信息摘要][7]
* [如何使用 lspci、lsscsi、lsusb 和 lsblk 获取 Linux 系统设备信息][8]
* [如何在 Linux 中检查系统硬件制造商、型号和序列号][9]
* [如何在 Linux 中查找 HBA 卡的 WWN、WWNN 和 WWPN 号][10]
* [如何从 Linux 命令行检查 HP iLO 固件版本][11]
* [如何从 Linux 命令行检查无线网卡和 WiFi 信息][12]
* [如何在 Linux 上检查 CPU 和硬盘温度][13]
* [Hegemon Linux 的模块化系统和硬件监视工具][14]
* [如何在 Linux 上检查系统配置和硬件信息][15]
如果你想为这个脚本增加其他的信息,请在评论去留下你的需求,以便我们帮助你。
@ -62,8 +54,10 @@ Linux 中有很多可以查看系统信息如处理器信息,生产商名字
这个脚本会在你每次登录 shell 时把系统信息打印到 terminal。
```
#vi /opt/scripts/system-info.sh
# vi /opt/scripts/system-info.sh
```
```
#!/bin/bash
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t"`hostname`
@ -90,12 +84,12 @@ df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0;}'
echo ""
echo -e "-------------------------------For WWN Details-------------------------------"
vserver=$(lscpu | grep vendor | wc -l)
vserver=$(lscpu | grep Hypervisor | wc -l)
if [ $vserver -gt 0 ]
then
echo "$(hostname) is a VM"
else
systool -c fc_host -v | egrep "(Class Device path | port_name |port_state)" > systool.out
cat /sys/class/fc_host/host?/port_name
fi
echo ""
@ -120,37 +114,37 @@ echo -e "-----------------------------------------------------------------------
fi
```
把上面脚本内容保存到一个文件 "system-info.sh",之后添加可执行权限
把上面脚本内容保存到一个文件 `system-info.sh`,之后添加可执行权限:
```
# chmod +x ~root/system-info.sh
```
当脚本准备好后,把脚本文件的路径加到 ".bash_profile" 文件末尾红帽系列的系统CentOSOracle Linux 和 Fedora
当脚本准备好后,把脚本文件的路径加到 `.bash_profile` 文件末尾红帽系列的系统CentOS、Oracle Linux 和 Fedora
```
# echo "/root/system-info.sh" >> ~root/.bash_profile
```
执行以下命令,来让修改的内容生效
执行以下命令,来让修改的内容生效
```
# source ~root/.bash_profile
```
对于 Debian 系统的系统,你可能需要把文件路径加到 ".profile" 文件中。
对于 Debian 系统的系统,你可能需要把文件路径加到 `.profile` 文件中:
```
# echo "/root/system-info.sh" >> ~root/.profile
```
运行以下命令使修改生效
运行以下命令使修改生效
```
# source ~root/.profile
```
你以前运行上面 "source" 命令时可能见过类似下面的输出。从下次开始,你在每次登录 shell 时会看到这些信息。当然,如果有必要你也可以随时手动执行这个脚本。
你以前运行上面 `source` 命令时可能见过类似下面的输出。从下次开始,你在每次登录 shell 时会看到这些信息。当然,如果有必要你也可以随时手动执行这个脚本。
```
-------------------------------System Information---------------------------
@ -203,7 +197,7 @@ via: https://www.2daygeek.com/bash-shell-script-view-linux-system-information/
作者:[Magesh Maruthamuthu][a]
选题:[lujun9972][b]
译者:[lxbwolf](https://github.com/lxbwolf)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
@ -212,3 +206,15 @@ via: https://www.2daygeek.com/bash-shell-script-view-linux-system-information/
[1]: https://www.2daygeek.com/category/shell-script/
[2]: https://www.2daygeek.com/category/bash-script/
[3]: https://www.2daygeek.com/inxi-system-hardware-information-on-linux/
[4]: https://www.2daygeek.com/dmidecode-get-print-display-check-linux-system-hardware-information/
[5]: https://www.2daygeek.com/lshw-find-check-system-hardware-information-details-linux/
[6]: https://www.2daygeek.com/hwinfo-check-display-detect-system-hardware-information-linux/
[7]: https://www.2daygeek.com/python-hwinfo-check-display-system-hardware-configuration-information-linux/
[8]: https://www.2daygeek.com/check-system-hardware-devices-bus-information-lspci-lsscsi-lsusb-lsblk-linux/
[9]: https://www.2daygeek.com/how-to-check-system-hardware-manufacturer-model-and-serial-number-in-linux/
[10]: https://www.2daygeek.com/how-to-find-wwn-wwnn-and-wwpn-number-of-hba-card-in-linux/
[11]: https://www.2daygeek.com/how-to-check-hp-ilo-firmware-version-from-linux-command-line/
[12]: https://www.2daygeek.com/linux-find-out-wireless-network-wifi-speed-signal-strength-quality/
[13]: https://www.2daygeek.com/view-check-cpu-hard-disk-temperature-linux/
[14]: https://www.2daygeek.com/hegemon-a-modular-system-and-hardware-monitoring-tool-for-linux/
[15]: https://www.2daygeek.com/check-linux-hardware-information-system-configuration/

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (chai-yuan)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,62 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Amazon joins the quantum computing crowd with Braket testbed)
[#]: via: (https://www.networkworld.com/article/3487421/amazon-joins-the-quantum-computing-crowd-with-braket-testbed.html)
[#]: author: (Jon Gold https://www.networkworld.com/author/Jon-Gold/)
Amazon joins the quantum computing crowd with Braket testbed
======
The newest part of AWS huge public-cloud ecosystem is Braket, a way for companies to experiment with quantum computing without having to own quantum computers.
Vizio
Amazons initial foray into the heavily hyped world of [quantum computing][1] is a virtual sandbox in which companies can test potential quantum-enabled applications and generally get to grips with the new technology, the company announced Monday.
The product is named Braket, after a system of notation used in quantum physics. The idea, according to Amazon, is to democratize access to quantum computing in a small way. Most organizations arent going to own their own quantum computers for the foreseeable future; theyre impractically expensive and require a huge amount of infrastructure even for the limited proof-of-concept models at the current cutting-edge.
[10 of the world's fastest supercomputers][2]
Hence, providing cloud-based access to three of those proofs-of-concept the D-Wave 2000Q, Rigetti 16Q , Aspen-4 and IonQ linear ion trap offers businesses the opportunity to learn firsthand about the way qubits work and how the basic building blocks of quantum programming might look. Braket will let users work remotely with those quantum computers or try out quantum algorithms in a classically driven simulated environment.
[][3]
BrandPost Sponsored by HPE
[Take the Intelligent Route with Consumption-Based Storage][3]
Combine the agility and economics of HPE storage with HPE GreenLake and run your IT department with efficiency.
“Our goal is to make sure you know enough about quantum computing to start looking for some appropriate use cases and conducting some tests and experiments,” said chief AWS evangelist Jeff Barr in [a blog post][4].
To help guide those efforts, Amazon also announced that it would form the AWS Center for Quantum Computing in partnership with Cal Tech. The idea here seems to be to create a center of excellence for research into both how quantum computers can be put to use and how they can be manufactured on a slightly larger scale. Furthermore, the new Amazon Quantum Solutions Lab would allow for a collaborative space in which companies can partner to share newfound expertise in quantum computing, as well as workshops and brainstorming sessions for education on quantum topics.
“Quantum computing is rapidly evolving, but the limited scale of the quantum hardware available today, fragmented development tools, and general shortage of quantum expertise, make it difficult to build near-term quantum applications,” said Amazon in a statement.
Quantum computing technology is still in the very early stages of development something like classical computing in the days of the Bletchley Park codebreaking machines, or ENIAC at the latest. Yet major tech companies have been eager to grab headlines in the field. Google boasted in October of [having achieved quantum supremacy][5], the ability to solve a problem with a quantum computer more quickly than with a classical one.
This sort of cloud-based quantum testbed isnt a wholly new idea. IBM has offered its Q Experience platform since 2016, and the company recently announced that more than 10 million experiments have been run there to date. And Amazons cloud rival Microsoft announced its Azure Quantum service just last month, offering a similar combination of cloud access, quantum programming tools, and remote access to prototype quantum computers.
Join the Network World communities on [Facebook][6] and [LinkedIn][7] to comment on topics that are top of mind.
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3487421/amazon-joins-the-quantum-computing-crowd-with-braket-testbed.html
作者:[Jon Gold][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Jon-Gold/
[b]: https://github.com/lujun9972
[1]: https://www.networkworld.com/article/3275367/what-s-quantum-computing-and-why-enterprises-need-to-care.html
[2]: https://www.networkworld.com/article/3236875/embargo-10-of-the-worlds-fastest-supercomputers.html
[3]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE20773&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
[4]: https://aws.amazon.com/blogs/aws/amazon-braket-get-started-with-quantum-computing/
[5]: https://www.networkworld.com/article/3447743/google-claims-quantum-supremacy-over-supercomputers.html
[6]: https://www.facebook.com/NetworkWorld/
[7]: https://www.linkedin.com/company/network-world

View File

@ -0,0 +1,157 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Java vs. Python: Which should you choose?)
[#]: via: (https://opensource.com/article/19/12/java-vs-python)
[#]: author: (Archit Modi https://opensource.com/users/architmodi)
Java vs. Python: Which should you choose?
======
Compare the two most popular programming languages in the world, and let
us know which one you prefer in our poll.
![Developing code.][1]
Let's compare the two most popular and powerful programming languages in the world: Java and Python! Both languages have huge community support and libraries to perform almost any programming task, although selecting a programming language usually depends on the developer's use case. After you compare and contrast, please make sure to answer our poll to [share your opinion][2] on which is best.
### What is it?
* **Java** is a general-purpose object-oriented programming language used mostly for developing a wide range of applications from mobile to web to enterprise apps.
* **Python** is a high-level object-oriented programming language used mostly for web development, artificial intelligence, machine learning, automation, and other data science applications.
### Creator
* **Java** was created by James Gosling (Sun Microsystems).
* **Python** was created by Guido van Rossum.
### Open source status
* **Java** is free and (mostly) open source except for corporate use.
* **Python** is free and open source for all use cases.
### Platform dependencies
* **Java** is platform-independent (although JVM isn't) per its WORA ("write once, run anywhere") philosophy.
* **Python** is platform-dependent.
### Compiled or interpreted
* **Java** is a compiled language. Java programs are translated to byte code at compile time and not runtime.
* **Python** is an interpreted language. Python programs are translated at runtime.
### File creation
* **Java**: After compilation, **<filename>.class** is generated.
* **Python**: During runtime, **<filename>.pyc** is created.
### Errors types
* **Java** has ****2 ****types of errors: compile and runtime errors.
* **Python** has 1 error type: traceback (or runtime) error.
### Statically or dynamically typed
* **Java** is statically typed. When initiating variables, their types need to be specified in the program because type checking is done at compile time.
* **Python** is dynamically typed. Variables don't need to have a type specified when initiated because type checking is done at runtime.
### Syntax
* **Java**: Every statement needs to end with a semicolon ( **;** ), and blocks of code are separated by curly braces ( **{}** ).
* **Python**: Blocks of code are separated by indentation (the user can choose how many white spaces to use, but it should be consistent throughout the block).
### Number of classes
* **Java**: Only one public top-level class can exist in a single file in Java.
* **Python**: Any number of classes can exist in a single file in Python.
### More or less code?
* **Java** generally involves writing more lines of code compared to Python.
* **Python** involves writing fewer lines of code compared to Java.
### Multiple inheritance
* **Java** does not support multiple inheritance (inheriting from two or more base classes)
* **Python** supports multiple inheritance although it is rarely implemented due to various issues like inheritance complexity, hierarchy, dependency issues, etc.
### Multi-threading
* **Java** multi-threading can support two or more concurrent threads running at the same time.
* **Python** uses a global interpreter lock (GIL), allowing only a single thread (CPU core) to run at a time.
### Execution speed
* **Java** is usually faster in execution time than Python.
* **Python** is usually slower in execution time than Java.
### Hello world in Java
```
public class Hello {
   public static void main([String][3][] args) {
      [System][4].out.println("Hello Opensource.com from Java!");
   }
}
```
### Hello world in Python
```
`print("Hello Opensource.com from Java!")`
```
### Run the programs
![Java vs. Python][5]
To run the java program "Hello.java" you need to compile it first which creates a "Hello.class" file. To run just the class name, use "java Hello." For Python, you would just run the file "python3 helloworld.py."
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/12/java-vs-python
作者:[Archit Modi][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/architmodi
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_development_programming.png?itok=M_QDcgz5 (Developing code.)
[2]: tmp.Bpi8QYfp8j#poll
[3]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
[4]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
[5]: https://opensource.com/sites/default/files/uploads/python-java-hello-world_0.png (Java vs. Python)

View File

@ -4,7 +4,7 @@
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to write a security integration module for Ansible)
[#]: via: (https://opensource.com/article/19/12/how-write-security-integration-module-ansible)
[#]: via: (https://opensource.com/article/19/12/security-ansible-module)
[#]: author: (Adam Miller https://opensource.com/users/maxamillion)
How to write a security integration module for Ansible
@ -149,7 +149,7 @@ If you have questions about Ansible module development models, feel free to reac
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/12/how-write-security-integration-module-ansible
via: https://opensource.com/article/19/12/security-ansible-module
作者:[Adam Miller][a]
选题:[lujun9972][b]

View File

@ -0,0 +1,131 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Solutions to the tiny window manager challenge)
[#]: via: (https://jvns.ca/blog/2019/12/03/solutions-to-the-tiny-window-manager-challenge/)
[#]: author: (Julia Evans https://jvns.ca/)
Solutions to the tiny window manager challenge
======
Hello! Last week I posted a small [programming challenge to write a tiny window manager that bounces windows around the screen][1].
![][2]
Ill write a bit about my experience of solving the challenge, or you can just skip to the end to see the solutions.
### whats a window manager?
An X window manager is a program that sends messages to the X server (which is in charge of drawing your windows) to tell it which windows to display and where.
I found out that you can trace those events with `xtrace`. Heres some example output from xtrace (for the toy window manager which is just moving windows about)
```
000:<:02d8: 20: Request(12): ConfigureWindow window=0x004158e5 values={x=560 y=8}
000:<:02da: 20: Request(12): ConfigureWindow window=0x004158e5 values={x=554 y=12}
000:<:02dc: 20: Request(12): ConfigureWindow window=0x004158e5 values={x=548 y=16}
000:<:02de: 20: Request(12): ConfigureWindow window=0x004158e5 values={x=542 y=20}
000:<:02e0: 20: Request(12): ConfigureWindow window=0x004158e5 values={x=536 y=24}
000:<:02e2: 20: Request(12): ConfigureWindow window=0x004158e5 values={x=530 y=28}
000:<:02e4: 20: Request(12): ConfigureWindow window=0x004158e5 values={x=524 y=32}
```
### you can run programs without a window manager
You technically dont _need_ a window manager to run graphical programs if you want to start an xterm in a window-manager-less X session you can just run
```
xterm -display :1
```
and itll start the xterm. Heres a screenshot of an X session with no window manager open. I even have 2 windows open! (chrome and an xterm). It has some major usability problems, for example I dont think you can resize or move or switch between windows. Which is where the window manager comes in!
<https://jvns.ca/images/no-wm.png>
### move a window with XMoveWindow
The challenge was to make the window bounce around the screen.
In the [tinywm source][3] they use `XMoveResizeWindow` to move and resize windows, but I found in the [docs][4] that theres also a function called `XMoveWindow`. Perfect!
Heres what it looks like. What could be simpler, right? And it works just the way Id expect!
```
XMoveWindow(display, windowID, x, y)
```
Except…
### problem: multiple `XMoveWindow`s dont work
I ran into a problem (which I got stuck on for a couple of hours) where when I ran XMoveWindow twice, it would only apply the last move.
```
XMoveWindow(display, windowID, 100, 200)
usleep(2000 * 1000); # sleep for 2 seconds
XMoveWindow(display, windowID, 300, 400)
```
Id expect this to move the window once, wait 2 seconds, and them move it again. But that was not what happened! Instead, it would pause for 2 seconds and then move the window once (to the second location).
### use xtrace to trace window manager events
I used xtrace to trace the events and found out that my `ConfigureWindow` events that `XMoveWindow` was sending were all being sent at the same time. So it seemed like X was batching the events. But why?
### XSync forces X to process events
I didnt know why this was happening, but I emailed Julian about it and he pointed me in the direction of [XSync][5], which forces X to process all the events youve sent it. Sure enough, I used XSync and everything worked beautifully.
### solutions
I asked people to email me if they completed the challenge, and 4 people did! Here are their solutions. All the solutions I got implemented more features than I did, so Id encourage you to look at all the solutions if youre interested in how to solve this problem!
* [Kacper Słomińskis solution][6] (which uses `XQueryTree` to find the windows to bounce, which is nice)
* [@whichxyjs solution][7]
* [Alexsey Lagoshins stressfulwm][8], which allows bouncing multiple windows:
* [Aldrin Martoq Ahumadas bouncywm-ruby][9], which is the only solution in a language other than C I got! It uses an Xlib Ruby library that looks pretty straightforward to use.
* one really nice one with fancier bouncing effects which Ill post here later if the person sends me the source
* [my solution][10]
Heres a gif of Alexseys solution. Apparently `XQuartz` on a Mac performs better than Xephyr!
![][11]
And Aldrins solution, with a great use of `xeyes`:
![][12]
### thanks!
Thanks to everyone who emailed me a solution, and if you write your own implementation Id love to post it here too, especially if you write one that isnt in C or Ruby! Im [[email protected]][13]
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2019/12/03/solutions-to-the-tiny-window-manager-challenge/
作者:[Julia Evans][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lujun9972
[1]: https://jvns.ca/blog/2019/11/25/challenge--make-a-bouncy-window-manager/
[2]: https://jvns.ca/images/bouncewm.gif
[3]: http://incise.org/tinywm.html
[4]: https://tronche.com/gui/x/xlib/window/XMoveWindow.html
[5]: https://tronche.com/gui/x/xlib/event-handling/XSync.html
[6]: https://gist.github.com/jvns/d5a0a4daf300f3dd7fa76d13b5aa2d53
[7]: https://github.com/whichxjy/bounce-wm/blob/master/bounce-wm.c
[8]: https://github.com/ayzenquwe/stressfulwm
[9]: https://github.com/aldrinmartoq/bouncywm-ruby
[10]: https://gist.github.com/jvns/c7a297fc4e17e797fd7b76b68860e55c
[11]: https://raw.githubusercontent.com/ayzenquwe/stressfulwm/d06531d286a5f00424bf12f7c77b18e11437ff20/gif/example.gif
[12]: https://raw.githubusercontent.com/aldrinmartoq/bouncywm-ruby/f6d424b6107c1349c8ee338b6a46c7116c6d1ea7/demo/demo.gif
[13]: https://jvns.ca/cdn-cgi/l/email-protection

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,273 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (4 ways to control the flow of your awk script)
[#]: via: (https://opensource.com/article/19/12/control-awk-script)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
4 ways to control the flow of your awk script
======
Learn to use switch statements and the break, continue, and next
commands to control awk scripts.
![JavaScript in Vim][1]
There are many ways to control the flow of an awk script, including [loops][2], **switch** statements and the **break**, **continue**, and **next** commands.
### Sample data
Create a sample data set called **colours.txt** and copy this content into it:
```
name       color  amount
apple      red    4
banana     yellow 6
strawberry red    3
raspberry  red    99
grape      purple 10
apple      green  8
plum       purple 2
kiwi       brown  4
potato     brown  9
pineapple  yellow 5
```
### Switch statements
The **switch** statement is a feature specific to GNU awk, so you can only use it with **gawk**. If your system or your target system doesn't have **gawk**, then you should not use a switch statement.
The **switch** statement in **gawk** is similar to the one in C and many other languages. The syntax is:
```
switch (expression) {
        case VALUE:
                &lt;do something here&gt;
        [...]
        default:
                &lt;do something here&gt;
}
```
The **expression** part can be any awk expression that returns a numeric or string result. The **VALUE** part (after the word **case**) is a numeric or string constant or a regular expression.
When a **switch** statement runs, the _expression_ is evaluated, and the result is matched against each case value. If there's a match, then the code contained within a case definition is executed. If there's no match in any case definition, then the default statement is executed.
The keyword **break** is at the end of the code in each case definition to break the loop. Without **break**, awk would continue to search for matching case values.
Here's an example **switch** statement:
```
#!/usr/bin/awk -f
#
# Example of the use of 'switch' in GNU Awk.
NR &gt; 1 {
    printf "The %s is classified as: ",$1
    switch ($1) {
        case "apple":
            print "a fruit, pome"
            break
        case "banana":
        case "grape":
        case "kiwi":
            print "a fruit, berry"
            break
                case "raspberry":
                        print "a computer, pi"
                        break
        case "plum":
            print "a fruit, drupe"
            break
        case "pineapple":
            print "a fruit, fused berries (syncarp)"
            break
        case "potato":
            print "a vegetable, tuber"
            break
        default:
            print "[unclassified]"
    }
}
```
This script notably ignores the first line of the file, which in the case of the sample data is just a header. It does this by operating only on records with an index number greater than 1. On all other records, this script compares the contents of the first field (**$1**, as you know from previous articles) to the value of each **case** definition. If there's a match, the **print** function is used to print the botanical classification of the entry. If there are no matches, then the **default** instance prints **"[unclassified]"**.
The banana, grape, and kiwi are all botanically classified as a berry, so there are three **case** definitions associated with one **print** result.
Run the script on the **colours.txt** sample file, and you should get this:
```
The apple is classified as: a fruit, pome
The banana is classified as: a fruit, berry
The strawberry is classified as: [unclassified]
The raspberry is classified as: a computer, pi
The grape is classified as: a fruit, berry
The apple is classified as: a fruit, pome
The plum is classified as: a fruit, drupe
The kiwi is classified as: a fruit, berry
The potato is classified as: a vegetable, tuber
The pineapple is classified as: a fruit, fused berries (syncarp)
```
### Break
The **break** statement is mainly used for the early termination of a **for**, **while**, or **do-while** loop or a **switch** statement. In a loop, **break** is often used where it's not possible to determine the number of iterations of the loop beforehand. Invoking **break** terminates the enclosing loop (which is relevant when there are nested loops or loops within loops).
This example, straight out of the [GNU awk manual][3], shows a method of finding the smallest divisor. Read the additional comments for a clear understanding of how the code works:
```
#!/usr/bin/awk -f
{
    num = $1
    # Make an infinite FOR loop
    for (divisor = 2; ; divisor++) {
        # If num is divisible by divisor, then break
        if (num % divisor == 0) {
            printf "Smallest divisor of %d is %d\n", num, divisor
            break
        }
        # If divisor has gotten too large, the number has no
        # divisor, so is a prime
        if (divisor * divisor &gt; num) {
            printf "%d is prime\n", num
            break
        }
    }
}
```
Try running the script to see its results:
```
    $ echo 67 | ./divisor.awk
    67 is prime
    $ echo 69 | ./divisor.awk
    Smallest divisor of 69 is 3
```
As you can see, even though the script starts out with an explicit _infinite_ loop with no end condition, the **break** function ensures that the script eventually terminates.
### Continue
The **continue** function is similar to **break**. It can be used in a **for**, **while**, or **do-while** loop (it's not relevant to a **switch** statements, though). Invoking **continue** skips the rest of the enclosing loop and begins the next cycle.
Here's another good example from the GNU awk manual to demonstrate a possible use of **continue**:
```
#!/usr/bin/awk -f
# Loop, printing numbers 0-20, except 5
BEGIN {
    for (x = 0; x &lt;= 20; x++) {
        if (x == 5)
            continue
        printf "%d ", x
    }
    print ""
}
```
This script analyzes the value of **x** before printing anything. If the value is exactly 5, then **continue** is invoked, causing the **printf** line to be skipped, but leaves the loop unbroken. Try the same code but with **break** instead to see the difference.
### Next
This statement is not related to loops like **break** and **continue** are. Instead, **next** applies to the main record processing cycle of awk: the functions you place between the BEGIN and END functions. The **next** statement causes awk to stop processing the _current input record_ and to move to the next one.
As you know from the earlier articles in this series, awk reads records from its input stream and applies rules to them. The **next** statement stops the execution of rules for the current record and moves to the next one.
Here's an example of **next** being used to "hold" information upon a specific condition:
```
#!/usr/bin/awk -f
# Ignore the header
NR == 1 { next }
# If field 2 (colour) is less than 6
# characters, then save it with its
#  line number and skip it
length($2) &lt; 6 {
    skip[NR] = $0
    next
}
# It's not the header and
# the colour name is &gt; 6 characters,
# so print the line
{
    print
}
# At the end, show what was skipped
END {
    printf "\nSkipped:\n"
    for (n in skip)
        print n": "skip[n]
}
```
This sample uses **next** in the first rule to avoid the first line of the file, which is a header row. The second rule skips lines when the color name is less than six characters long, but it also saves that line in an array called **skip**, using the line number as the key (also known as the _index_).
The third rule prints anything it sees, but it is not invoked if either rule 1 or rule 2 causes it to be skipped.
Finally, at the end of all the processing, the **END** rule prints the contents of the array.
Run the sample script on the **colours.txt** file from above (and previous articles):
```
$ ./next.awk colours.txt
banana     yellow 6
grape      purple 10
plum       purple 2
pineapple  yellow 5
Skipped:
2: apple      red    4
4: strawberry red    3
6: apple      green  8
8: kiwi       brown  4
9: potato     brown  9
```
### Control freak
In summary, **switch**, **continue**, **next**, and **break** are important preemptive exceptions to awk rules that provide greater control of your script. You don't have to use them directly; often, you can gain the same logic through other means, but they're great convenience functions that make the coder's life a lot easier. The next article in this series covers the **printf** statement.
* * *
Would you rather listen to this article? It was adapted from an episode of [Hacker Public Radio][4], a community technology podcast by hackers, for hackers.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/12/control-awk-script
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/javascript_vim.jpg?itok=mqkAeakO (JavaScript in Vim)
[2]: https://opensource.com/article/19/11/loops-awk
[3]: https://www.gnu.org/software/gawk/manual/
[4]: http://hackerpublicradio.org/eps.php?id=2438

View File

@ -0,0 +1,61 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Complementary engineering indicators)
[#]: via: (https://dave.cheney.net/2019/12/04/complementary-engineering-indicators)
[#]: author: (Dave Cheney https://dave.cheney.net/author/davecheney)
Complementary engineering indicators
======
Last year I had the opportunity to watch Cat Swetels presentation _[The Development Metrics You Should Use (but Dont)][1]_. The information that could be gleaned from just tracking the start and finish date of work items was eye opening. If youre using an issue tracker this information is probably already (perhaps with some light data munging) available — no need for TPS reports. Additionally, statistics obtained by data mining your projects issue tracker are, perhaps, less likely to be juked.
Around the time I saw Cats presentation I finished reading Andy Groves _High Output Management_. The hidden gem in this book (assuming becoming a meeting powerhouse isnt your bag) was Groves notion of indicator pairs. An example of a paired indicator might be the number of sales deals closed paired with the customer retention rate. The underling principle being optimising for one indicator will have an adverse impact on the other. In the example, overly aggressive or deceptive tactics could superficially raise the number of sales made, but would be reflected in a dip in the retention rate as customers returned the product or terminated their service prematurely.
These ideas lead me to thinking about indicators you could use for a team delivering a software product. Could those indicators be derived cheaply from the hand to hand combat of software delivery? Could they be structured in a way that aggressively pursuing one metric would be reflected negatively in another? I think so.
These are the three metrics that Ive been using to track the health of the project that I lead.
* Date; was the software done when we said it would be done. If you prefer this indicator as a scalar, how many days difference is there between the ship date agreed on at the start of the sprint/milestone/whatever and what was the actual date that you considered it done.
* Completeness; when the software is done, how many of the things we said were going to do actually got delivered in that release.
* Defects reported; once the software is in the field, what is the rate of bugs reported.
It is relatively easy, for example, to hit a delivery date if you aggressively descope anything risky or simply dont do it. But in doing so this lack of promised functionality would impact the completeness metric.
Conversely, its straight forward to hit your milestones completeness target if you let the release date slip and slip. Bringing both the metics into line requires good estimation skills to judge how much can be attempted in milestone and provide direct feedback if your estimation skills needed work.
The third indicator, defects reported in the field, acts as a check on the other two. It would be easy to consistent hit your delivery date with 100% feature completion if your team does a shoddy job. The high fives and 🎉 emojis will be short lived if each release brings with it a swathe of high priority bug reports. This indicator also tends to have a second order effect, rushed features to meet a deadline tend to generate remedial work in the following milestones, crowding out promised work or blowing later deadlines.
I consider these to be complementary metrics, they should be considered together, as a group, rather than individually. Ideally your team should be delivering what you promised, when you promised it, with a low defect rate. But more importantly, if that isnt the case, if one of the indicators is unhealthy, addressing it shouldnt result in the problem moving to another.
### Related posts:
1. [Never edit a method, always rewrite it][2]
2. [The Mythical Man-Month selection bias][3]
3. [The office coffee model of concurrent garbage collection][4]
4. [Sydney High Performance Go workshop][5]
--------------------------------------------------------------------------------
via: https://dave.cheney.net/2019/12/04/complementary-engineering-indicators
作者:[Dave Cheney][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://dave.cheney.net/author/davecheney
[b]: https://github.com/lujun9972
[1]: https://www.youtube.com/watch?v=cW3yM-K2M08
[2]: https://dave.cheney.net/2017/11/30/never-edit-a-method-always-rewrite-it (Never edit a method, always rewrite it)
[3]: https://dave.cheney.net/2013/12/04/the-mythical-man-month-selection-bias (The Mythical Man-Month selection bias)
[4]: https://dave.cheney.net/2018/12/28/the-office-coffee-model-of-concurrent-garbage-collection (The office coffee model of concurrent garbage collection)
[5]: https://dave.cheney.net/2019/07/05/sydney-high-performance-go-workshop (Sydney High Performance Go workshop)

View File

@ -0,0 +1,68 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Spice up your Linux desktop with Cinnamon)
[#]: via: (https://opensource.com/article/19/12/cinnamon-linux-desktop)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Spice up your Linux desktop with Cinnamon
======
This article is part of a special series of 24 days of Linux desktops.
Just like its namesake, the Cinnamon Linux desktop is warm and inviting
and cozy.
![Cinnamon][1]
When GNOME 3 was released, some GNOME users were not ready to give up GNOME 2. The [Linux Mint][2] project was so dissatisfied with GNOME 3 that it started its own desktop as an alternative, and thus the [Cinnamon][3] desktop was born.
Cinnamon originally sought to "remix" GNOME 3 so that it looked and acted like the GNOME 2 so many users knew and loved, but eventually, it diverged enough to be a true fork. Today, Cinnamon uses GTK3 libraries and forked versions of key GNOME 3 applications to create a classic GNOME experience.
You may find Cinnamon in your distribution's software repository, or you can download and install a distribution that ships with Cinnamon as its default desktop. Before you do, though, be aware that it is meant to provide a full desktop experience, so many Cinnamon apps are installed along with the desktop. If you're already running a different desktop, you may find yourself with redundant applications (two PDF readers, two media players, two file managers, and so on).
If you just want to try the Cinnamon desktop, you can install a Cinnamon-based distribution in a virtual machine, such as [GNOME Boxes][4].
### Cinnamon desktop tour
The Cinnamon desktop layout has a classic look, although—in spite of being inspired by GNOME 2—that look is not at all like GNOME 2. In fact, it shares more with KDE's Plasma desktop than with GNOME 2, with an application menu in the lower-left corner, a taskbar for pinned and active applications, and a system tray in the lower-right corner. There's no top menu bar with Applications and Places and System menus, and the taskbar uses icons with no text, so if it's a clone of GNOME 2 you're looking for, Cinnamon doesn't provide that.
![Cinnamon desktop on Linux Mint][5]
What Cinnamon does provide, however, is the opportunity for Linux Mint developers to control the environment they maintain. The Mint desktop is very much a Linux Mint creation, so much so that it's almost a part of the Mint brand. And yet it's appealing enough for enough users that it's available on [other distributions][6], even ones traditionally seen as "rivals" (at least, insofar as there are rivalries in open source). Here's the Cinnamon desktop environment fitting in nicely with a Fedora install:
![Cinnamon desktop on Fedora][7]
The desktop experience, aside from its panel layout, is a simple and classic one. There are icons on the desktop serving as shortcuts to common locations, there's an application for most file-management tasks, and there are applets in the systems tray for common administrative tasks. It's a familiar user experience. Just like its name, it's warm and inviting and cozy.
### Customizing the desktop
Cinnamon isn't as flexible as something like Fluxbox or KDE, but it's not as rigid as GNOME 3 or Pantheon. The System Settings application provides customization for all the usual small details, such as keyboard layout, keyboard shortcuts, workspace behavior, a firewall, and so on. A right-click on any element usually brings up a useful contextual menu with settings or information about what you've clicked.
There are definitely some expectations about what your workflow ought to be when using Cinnamon, but these assumptions are all generic and safe. It may not be the most efficient desktop environment, but it's soundly a generic, all-purpose one. Both power users and new users feel at home in Cinnamon. You can customize the experience within certain parameters, and if you hit the ceiling when you try to make drastic changes, then you can fall back on the fact that this is open source, and you have plenty of other options.
You may never hit that ceiling, though. Cinnamon's an attractive and responsive interface. It's a pleasure to use because it's simple and intuitive, with no surprises or puzzling user-interface choices to slow you down. With a few custom keyboard shortcuts and a little time to settle into a new environment, you can do amazing things with Cinnamon, and you'll love every moment of it because it's a beautiful thing to witness. Cinnamon is restrained with animations and effects, and the ones it uses are appealing and even informative.
### Spice of life
It's fun to try new desktops, and Cinnamon is worth trying. Install or download it today and see what you think. It's one of those desktops that you already know how to use, even if you've never used it before.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/12/cinnamon-linux-desktop
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cinnamon.jpg?itok=4GV-boum (Cinnamon)
[2]: https://www.linuxmint.com/
[3]: https://github.com/linuxmint/Cinnamon
[4]: https://opensource.com/article/19/5/getting-started-gnome-boxes-virtualization
[5]: https://opensource.com/sites/default/files/uploads/advent-cinnamon.jpg (Cinnamon desktop on Linux Mint)
[6]: https://en.wikipedia.org/wiki/Cinnamon_(desktop_environment)#Adoption
[7]: https://opensource.com/sites/default/files/uploads/advent-cinnamon-fedora.jpg (Cinnamon desktop on Fedora)

View File

@ -7,20 +7,20 @@
[#]: via: (https://fedoramagazine.org/a-quick-introduction-to-toolbox-on-fedora/)
[#]: author: (Ryan Walter https://fedoramagazine.org/author/rwaltr/)
A quick introduction to Toolbox on Fedora
快速介绍 Fedora 中的 Toolbox
======
![][1]
Toolbox allows you to [sort and manage your development environments in containers][2] without requiring root privileges or manually attaching volumes. It creates a container where you can install your own CLI tools, without installing them on the base system itself. You can also utilize it when you do not have root access or cannot install programs directly. This article gives you an introduction to toolbox and what it does.
Toolbox 使你可以[在容器中分类和管理开发环境][2],而无需 root 权限或手动添加卷。它创建一个容器你可以在其中安装自己的命令行工具而无需在基础系统中安装它们。当你没有root 权限或无法直接安装程序时,也可以使用它。本文会介绍 Toolbox 及其功能。
### Installing Toolbox
### 安装 Toolbox
[Silverblue][3] includes Toolbox by default. For the Workstation and Server editions, you can grab it from the default repositories using _dnf install toolbox_.
[Silverblue][3] 默认包含 Toolbox。对于 Workstation 和 Server 版本,你可以使用 _dnf install toolbox_ 从默认仓库中获取它。
### Creating Toolboxes
### 创建 Toolbox
Open your terminal and run _toolbox enter_. The utility will automatically request permission to download the latest image, create your first container, and place your shell inside this container.
打开终端并运行 _toolbox enter_。程序将自动请求许可来下载最新的镜像,创建第一个容器并将你的 shell 放在该容器中。
```
$ toolbox enter
@ -29,7 +29,7 @@ Image required to create toolbox container.
Download registry.fedoraproject.org/f30/fedora-toolbox:30 (500MB)? [y/N]: y
```
Currently there is no difference between the toolbox and your base system. Your filesystems and packages appear unchanged. Here is an example using a repository that contains documentation source for a resume under a _~/src/resume_ folder. The resume is built using the _pandoc_ tool.
当前toolbox 和你的基本系统之间没有区别。你的文件系统和软件包未更改。这是一个使用仓库的示例,它包含 _~/src/resume_ 文件夹下的简历的文档源。简历是使用 _pandoc_ 工具构建的。
```
$ pwd
@ -47,7 +47,7 @@ $ pandoc -v
bash: pandoc: command not found
```
This toolbox does not have the programs required to build the resume. You can remedy this by installing the tools with _dnf_. You will not be prompted for the root password, because you are running in a container.
这个 toolbox 没有构建简历所需的程序。你可以通过使用 _dnf_ 安装工具来解决此问题。由于正在容器中运行,因此不会提示你输入 root 密码。
```
$ sudo dnf groupinstall "Authoring and Publishing" -y && sudo dnf install pandoc make -y
@ -63,7 +63,7 @@ $ ls BUILDS/
resume.docx resume.html resume.pdf resume.rtf resume.txt
```
Run _exit_ at any time to exit the toolbox.
运行 _exit_ 退出 toolbox。
```
$ cd BUILDS/
@ -80,21 +80,20 @@ bash: pandoc: command not found...
resume.docx resume.html resume.pdf resume.rtf resume.txt
```
You retain the files created by your toolbox in your home directory. None of the programs installed in your toolbox will be available outside of it.
你会在主目录中得到由 toolbox 创建的文件。toolbox 中安装的程序无法在外部访问。
### Tips and tricks
### 提示和技巧
This introduction to toolbox only scratches the surface. Here are some additional tips, but you can also check out [the official documentation][2].
* _Toolbox help_ will show you the man page for Toolbox
* You can have multiple toolboxes at once. Use _toolbox create -c Toolboxname_ and _toolbox enter -c Toolboxname_
* Toolbox uses [Podman][4] to do the heavy lifting. Use _toolbox list_ to find the IDs of the containers Toolbox creates. Podman can use these IDs to perform actions such as _rm_ and _stop_. (You can also read more about Podman [in this Magazine article][5].)
本介绍仅涉及 toolbox 的表明。还有一些其他提示,但是你也可以查看[官方文档][2]。
* _Toolbox help_ 会显示 Toolbox 的手册页
* 你可以一次有多个 toolbox。使用 _toolbox create -c Toolboxname__toolbox enter -c Toolboxname_
* Toolbox 使用 [Podman][4] 来完成繁重的工作。使用 _toolbox list_ 查找 Toolbox 创建的容器的 ID。Podman 可以使用这些 ID 来执行 _rm__stop_ 之类的操作。 (你也可以在[此文章][5]中阅读有关 Podman 的更多信息。)
* * *
_Photo courtesy of [Florian Richter][6] from [Flickr][7]._
_照片出自 [Flickr][7] 的 [Florian Richter][6]。_
--------------------------------------------------------------------------------
@ -102,7 +101,7 @@ via: https://fedoramagazine.org/a-quick-introduction-to-toolbox-on-fedora/
作者:[Ryan Walter][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -7,28 +7,28 @@
[#]: via: (https://fedoramagazine.org/using-ansible-to-organize-your-ssh-keys-in-aws/)
[#]: author: (Daniel Leite de Abreu https://fedoramagazine.org/author/dabreu/)
Using Ansible to organize your SSH keys in AWS
在 AWS 中使用 Ansible 来管理你的 SSH keys
======
![][1]
If youve worked with instances in Amazon Web Services (AWS) for a long time, you may run into this common issue. Its not technical, but more to do with the human nature of getting too comfortable. When you launch a new instance in a region you havent used recently, you may end up creating a new SSH key pair. This leads to having too many keys, which can become complicated and disordered.
如果你长期使用亚马逊Web服务AWS中的实例你可能会遇到下面这个常见的问题它不是因为技术性的原因导致的更多的是因为人类追求方便舒适的天性当你登录一台你最近没有使用的区域的实例你最终就会创建一个新的SSH密钥对久而久之这最终就会造成个人拥有太多密钥导致管理起来复杂混乱。
This article shows you a way to have your public key in all regions. A recent [Fedora Magazine article][2] includes one solution. But the solution in this article is automated even further, and in a more concise and scalable way.
本文将会介绍一种在所有区域中使用你的公钥的方法。最近,一篇[Fedora Magazine article][2]介绍了另一种解决方案。但本文中的解决方案可以进一步的以更简洁和可扩展的方式实现自动化。
Say you have a Fedora 30 or 31 desktop system where your key is stored, and Ansible is installed as well. These two things together provide the solution to this problem and many more.
假设你有一个Fedora 30或31系统其中存储了你的密钥并且还安装了Ansible。当这两件事同时满足时就提供了解决这个问题的办法甚至它还能做到更多。
With Ansibles [ec2_key module][3], you can create a simple playbook that will maintain your SSH key pair in all regions. If you need to add or remove keys, its as simple as adding and removing lines from a file.
使用Ansible的[ec2_key 模块][3]你可以创建一个简单的playbook来在所有区域中维护你的SSH密钥对。如果你需要增加或者删除密钥在ansible中这就像从文件中添加和删除行一样简单。
### Setting up and running the playbook
### 设置和运行 playbook
To use the playbook, first install necessary dependencies for the _ec2_key_ module:
如果要使用playbook首先需要安装 _ec2_key_ 模块的必要依赖项:
```
$ sudo dnf install python3-boto python3-boto3
```
The playbook is simple: you need only to change your key and its name as in the example below. After that, run the playbook and it iterates over all the public AWS regions listed. The example also includes the restricted regions in case you have access. To include them, uncomment each line as needed, save the file, and then run the playbook again.
playbook很简单你只需要像下面的例子一样修改其中的密钥及其对应的名称。然后运行playbook它会帮你遍历所有列出的公共AWS区域。该示例还包括一些受限区域以防你有访问权限只需根据需要来取消对应行的注释然后保存文件重新运行playbook即可。
```
---
@ -71,37 +71,34 @@ The playbook is simple: you need only to change your key and its name as in the
# - cn-northwest-1 #China (Ningxia)
```
This playbook requires AWS access via API, as well. To do this, use environment variables as follows:
这个playbook需要通过API访问AWS为此请使用环境变量如下所示
```
$ AWS_ACCESS_KEY="aws-access-key-id" AWS_SECRET_KEY="aws-secret-key-id" ansible-playbook ec2-playbook.yml
```
Another option is to install the aws cli tools and add the credentials as explained in a [previous Fedora Magazine article][4]. It is **not recommended** to insert these values in the playbook if you store it anywhere online! You can find this playbook code on [GitHub][5].
另一个选项是安装aws cli工具并添加凭据如以前的一篇[Fedora Magazine article][4]文章所述。如果你在线存储它们这些参数将不建议插入到playbook中你可以在[GitHub][5]中找到本文的playbook代码。
After the playbook finishes, confirm that your key is available on the AWS console. To do that:
完成playbook之后请确认你的密钥在AWS控制台上可用。为此可以做如下操作
1. 登录你的AWS控制台
2. 转到 **EC2 &gt; Key Pairs**
3. 您应该会看到列出的密钥。唯一的限制是你必须使用此方法逐个区域来检查。
1. Log into your AWS console
2. Go to **EC2 &gt; Key Pairs**
3. You should see your key listed. The only limitation is that you have to check region-by-region with this method.
另一种方法是在shell中使用一个快速命令来为你做这些检查。
Another way is to use a quick command in a shell to do this check for you.
First create a variable with all regions on the playbook:
首先在playbook上创建一个包含所有区域的变量
```
AWS_REGION="us-east-1 us-west-1 us-west-2 ap-east-1 ap-south-1 ap-northeast-2 ap-southeast-1 ap-southeast-2 ap-northeast-1 ca-central-1 eu-central-1 eu-west-1 eu-west-2 eu-west-3 eu-north-1 me-south-1 sa-east-1"
```
Then do a for loop and you will get the result from aws API:
然后执行如下循环你就可以从aws的API获得结果
```
for each in ${AWS_REGION} ; do aws ec2 describe-key-pairs --key-name <YOUR KEY GOES HERE> ; done
```
Keep in mind that to do the above you need to have the aws cli installed.
请记住,要执行上述操作,您需要安装 aws cli。
--------------------------------------------------------------------------------
@ -109,7 +106,7 @@ via: https://fedoramagazine.org/using-ansible-to-organize-your-ssh-keys-in-aws/
作者:[Daniel Leite de Abreu][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[hj24](https://github.com/hj24)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出