Bash Scripting: Why didn’t I start this earlier?

时间:2021-02-17 00:33:39

英文:Bash Scripting: Why didn’t I start this earlier?

原译文:bash脚本:为什么我这么迟才用?


I’m a little embarrassed to admit this. I’ve been building software for fifteen years, and I’m only just now getting into bash scripting.

我提交这篇文章时有点尴尬。因为我这已经是我在软件行业的第15个年头了,而我才刚刚开始玩bash脚本。

I had never seen myself as a “DevOps guy” or a “Systems Administrator”, so I knew just enough to build good, sturdy, secure servers with little flash and lots of functionality. No flare. No grace. I concentrated on software.

我从来没觉得自己是一个强力的“开发协调者”或者“系统管理员”, 我的知识只是刚好够用一些flash和大量的函数去建立一个漂亮,强健和安全的服务器。既不华丽,也不优雅地专注软件开发。

But in the last year or so, I’ve come to embrace “Unix as an IDE”. (Before that, I was a MacVim guy.) The tools are impressive and robust, and having a remotely hosted, SSH-driven development environment is just so convenient and enjoyable. As a result, I’ve logged nearly a thousand hours on my dev server via iTerm and an SSH connection in the last 6 months.

但在过去的一年左右,我开始信奉“unix 即ide”,(在那之前,我曾是一名macvim使用者)。这个工具实在令人敬佩,他很强健,有一个远程主机,以SSH驱动的开发环境非常方便,在上面开发简直是种享受。就因为这样,我通过终端和一个SSH连接在最近6个月内登录了将近1000小时。


Despite my growing comfort with the command line, I never really concentrated too much on automating my sysadmin tasks.No premature optimization, I thought. I did everything by hand. All the server builds, the maintenance and upkeep, all done one line at a time. I’ve even tried Chef and other related tools; I just didn’t like them.

尽管我越来越适应命令行式编程,但是我从来没有话太多精力在自动化我的管理员任务上。不要过早的优化,我想。我手动完成所有的东西。所有的服务器建设,维护和修复,都是通过一次一行命令来完成的。我曾经尝试过chef和其他相关的工具;但是我就是不喜欢。


But last week I ran into a problem: we had a huge increase in traffic and activity.We needed to scale significantly, andfast. I was used to building one server at a time,at my leisure, all by hand. (I’ve always felt a zen calm while building servers, so I enjoyed building them by hand.) But that wouldn’t cut it now. I needed 8 new app servers in the next few hours.

最近一个星期我遇到一个问题,网络流量和连接数大增,我需要一个很大的扩容,而且要快。我习惯于不紧不慢地,一次建立一个服务器,全部手工完成。(在创建服务器的时候我能感到禅意,所以我很享受手动创建。)但是现在不得不减少这个时间了。我需要在之后的几个小时内创建8个新的服务器程序。


I bit the bullet and wrote the first real (ie, longer than 10 lines) bash script I’ve ever written — to automate my app server builds. While I had the server build procedure committed to memory, it still took me about 90 minutes to write the script and work out all the kinks. (I had a few issues with accidentally calling the script from the wrong path, and made some other similar newbie mistakes.)

我咬紧牙关,写了第一个真正的(大于10行)的bash脚本,来自动化我的服务器程序创建。虽然做到了讲build进程提交到服务器内存,但这还是这花了我90分钟的时间去写这个脚本和解决全部错误。(调用脚本时找错路径,还有一些初哥才会犯的错误。)


But the payoff was the most exciting part. This 90-minute investment of my time ended up transforming what used to be a 30 minute, manual, and error-prone server build process into a perfect lean, mean, server building machine. Now it only takes me 5 minutes to build a server, and they’re all perfectly configured out of the box. All due to a crash course in bash scripting.

但收获却令我十分兴奋。这90分钟的投入将之前需要30分钟,手动,容易出错的服务器build过程变成一调完美的服务器build生产线.现在只需要5分钟就可以创建一个服务器,并且全部都是完美配置好的.而这全都归功于我刚学的bash脚本.


Part of me wishes it hadn’t taken me 15 years to get to this point, but the other part of me recognizes that everyone learns their lessons in a different order. Either way, I’m happy to have finally added bash to my toolbelt.

一方面我庆幸那没有花费我15年去搞明白这个道理,另一方面,我觉得每个人摄取经验教训有早有晚。无论怎么样,我都很高兴最后我把bash添加到我的工具集中.


What do you guys do? How do you manage your server builds and automation? I’d love to see what the full spectrum looks like.

你们是怎么样做得呢?怎么管理自己的服务器创建和自动化操作的?我很想看看这一系列的做法是怎么样的。



后记:

第一篇(超过10行Bash Scripting: Why didn’t I start this earlier?)全由个人完成翻译的文章~,翻译完之后有不明确的地方参考了译言网 Elaine.Ye的翻译。

紫色字是不明确的地方。

希望透过这样的方式快速提高自己的英语阅读水平吧。

另对比别人的翻译我自己的翻译,别人会比自己译的更为谦卑,语气更为平和,是自己太浮躁了(因为自己在翻译的时候就觉得原作者怎么这么迟才悟得“自动化”这个道理)。


ps:不知道这个能不能转。如有冒犯,请多包涵。