shell脚本编写

tech2024-04-20  85

shell脚本编写

The command line is many things to many people. Some users run in horror, preferring a GUI for point and click administration. Others will not work anywhere but in the warm glow of the Bash Shell.

命令行对很多人来说是很多事情。 一些用户惊恐地运行,更喜欢使用GUI进行点击管理。 其他人将无法在任何地方使用,除非在Bash Shell的温暖光芒下。

I live in both worlds, having found wonderful system administration solutions in the open source world, my favorite being Webmin. However, I continually return the the command shell for many of my tasks and scripting needs. This has become even more convenient in my case using Mac OS X as my OS, having the benefit of a world-class GUI and the underlying BSD Unix tools.

我生活在两个世界中,在开源世界中找到了很棒的系统管理解决方案,我最喜欢的是Webmin 。 但是,我会为我的许多任务和脚本需求不断返回命令外壳。 在我使用Mac OS X作为我的操作系统的情况下,这变得更加方便,这得益于世界级的GUI和基础的BSD Unix工具。

For some time I have considered myself quite adept on the command line. That was until Chris Johnson’s Shell Scripting Recipes (Apress) landed on my desk. Johnson was introduced to Unix and the shell in 1990, 5 years before I had that pleasure and has surely become a master.

一段时间以来,我认为自己在命令行方面相当熟练。 直到Chris Johnson的Shell脚本编写食谱 (Apress)降落在我的桌子上。 Johnson在1990年被介绍给Unix和Shell,这比我高兴的那五年还早已成为大师。

Taking a step back – many of us who manage servers will use the shell for SFTP or SSH sessions, managing applications such as MySQL, mail servers, web servers and so on. Additionally, we frequently will write some useful scripts for exercises such as backing up data, replicating to other servers, checking logs and cleaning up caches and queues.

退一步–我们中许多管理服务器的人将使用Shell进行SFTP或SSH会话,管理MySQL,邮件服务器,Web服务器等应用程序。 此外,我们经常会编写一些有用的脚本进行练习,例如备份数据,复制到其他服务器,检查日志以及清理缓存和队列。

Johnson takes the shell to the next level, providing an extended look across utilities and functions capable of handling serious sophistication or even constructing applications to run on the command line, whether they are to be used for system administration or for some of our more advanced users or clients with technical staff managing their own domains.

Johnson将外壳程序提升到了一个新的高度,无论是用于系统管理还是为某些更高级的用户使用,它们都可以扩展实用程序和功能的扩展视图,这些实用程序和功能可以处理严重的复杂问题,甚至可以构建可在命令行上运行的应用程序或拥有技术人员管理自己的域的客户。

Johnson starts appropriately with an introduction to the core functions and utilities available in the POSIX shell. This allows readers of his book to leverage this knowledge in today’s common shells, one way or another descendants of the POSIX shell. I did think the first chapter could have been more of an overview rather than diving right into an outline of Unix functions – which may be a stumbling block for brand new shell users. Though anyone with some command line experience should not have an issue getting into gear with the content.

Johnson适当地介绍了POSIX Shell中可用的核心功能和实用程序。 这使他的书的读者可以以当今的通用外壳(一种或多种POSIX外壳的后代)利用这些知识。 我确实认为第一章可能更多是概述,而不是直接深入研究Unix函数的概述–对于新的shell用户来说,这可能是绊脚石。 尽管具有一定命令行经验的任何人都应该在适应内容方面没有问题。

Beyond the introduction, Shell Scripting Recipes gets serious, breaking down shell capabilities by functions – looking at manipulation of text files, dealing with strings, math functions, working with dates and more.

除了介绍之外,Shell脚本食谱变得越来越重要,通过功能分解了Shell功能-查看文本文件的操作,处理字符串,数学函数,使用日期等。

I found several chapters very beneficial to issues I deal with. First up was working with PATH (Chapter 7), which most of us have wrestled with building applications on Linux systems. Johnson’s provides three useful scripts (checkpath, addpath and rmpath) which allow an admin to deal with user paths. This can come in handy for those with clients running custom built apps on your servers.

我发现有几章对我处理的问题非常有益。 首先是使用PATH(第7章),我们大多数人都在为在Linux系统上构建应用程序而苦苦挣扎。 Johnson's提供了三个有用的脚本(checkpath,addpath和rmpath),这些脚本允许管理员处理用户路径。 对于客户端在您的服务器上运行定制应用程序的客户而言,这可能会派上用场。

Staying on the end user theme – I was thrilled to get introduced to pop3-funcs (Chapter 10). This introduces capabililities for troubleshooting pop mailboxes on many levels, from simple message and size counts to collecting message headers into an array for review or filtering manually from a technical support perspective. Additionally, Johnson covers pop3list, which acts like a pseudo email client in the shell. I found this an ideal tool for testing needs perhaps to verify delivery of messages to a client mailbox when rolling out a web app (or patching it) rather than configuring my own client to test a domain I will not use.

坚持最终用户主题–我很高兴被pop3-funcs入门(第10章)。 从简单的邮件和大小计数到将邮件标头收集到一个数组中以从技术支持的角度进行手动查看或筛选,这引入了从多个级别对弹出邮箱进行故障排除的功能。 此外,Johnson还介绍了pop3list,其作用类似于shell中的伪电子邮件客户端。 我发现这是一个测试的理想工具,可能需要在推出Web应用程序(或对其进行修补)时验证消息是否已发送到客户端邮箱,而不是配置自己的客户端来测试我将不使用的域。

In Chapter 16, Johnson tunes into the world of HTML with some useful utilities I will make use of. I can think of many intranet and extranet uses for his mk-htmlindex, which indexes a directory of files without an index.html file and overrides Apache default settings. This allows one to format and control the header of the file while creating a directory listing. Not anything new, but I did also like Johnson’s text2html script, which converts text files to html. I have had many instances where I needed to convert numerous files to simple html. This may save me time compared to my normal process of loading the text files into a Dreamweaver and applying a template one by one.

在第16章中,Johnson使用了一些有用的实用工具来进入HTML的世界。 我可以想到他的mk-htmlindex的许多Intranet和Extranet用途,该索引索引没有index.html文件的文件目录,并覆盖Apache的默认设置。 这样,在创建目录列表时,就可以格式化和控制文件的标题。 并不是什么新鲜事物,但是我也很喜欢Johnson的text2html脚本,该脚本将文本文件转换为html。 我有很多需要将大量文件转换为简单html的实例。 与将文本文件加载到Dreamweaver并逐个应用模板的正常过程相比,这可以节省我的时间。

In the end – Johnson has written a book that looks at the shell from several perspectives:

最后,约翰逊写了一本书,从多个角度审视了壳:

as a powerful utility for the command line user,

作为命令行用户的强大工具, as an application environment for advanced users,

作为高级用户的应用程序环境, as a deep library of functions for system administrators.

作为系统管理员的深层功能库。

There is likely something for every type of shell user in Shell Scripting Recipes, as a glance at the table of contents (PDF) should reflect.

概览目录 (PDF)应该反映出Shell脚本食谱中每种类型的Shell用户可能都有的东西。

翻译自: https://www.sitepoint.com/shell-scripting-recipes/

shell脚本编写

相关资源:startupkit-DF:该仓库提供了dockerfile和脚本,供人们尽快上手-源码
最新回复(0)