如何以编程方式验证 CYGWIN 应用程序是否安装在 SH 脚本中?
情况如下:
我正在编写一个 SH 部署脚本,该脚本将在 CYGWIN 中使用 RSYNC 命令部署网站。 安装完成后,我想向开发团队发送一封电子邮件,说明已经进行了部署并提供了一些详细信息。 我将使用“exim”从 CYGWIN 发送邮件。
问题是,exim 仅在安装 CYGWIN 时是可选的,如果未安装,我想退出我的 SH 脚本。 如果应用程序安装在脚本中,是否有想法检查 UNIX(并在 CYGWIN 中工作)?
提前致谢 !
Here's the situation :
I am writing a SH deployment script that will deploy a website with an RSYNC command in CYGWIN. After the installation, I want to send an e-mail to the development team to say that a deployment has been made with some details. I will use "exim" to send the mail from CYGWIN.
The thing is that, exim is only optional when installing CYGWIN and I would like to quit my SH script if it's not installed. Any idea to check in UNIX (and working in CYGWIN) if an app is installed in a script ?
Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
具体来说,要检查“exim”,请
在我的 Cygwin 上执行,它会给出类似的输出,
来自“exim”手册中的“exim -bV”,
与
type
和which
检查进行比较。type 是 shell 内置命令。 它指示如果用作命令,shell 将如何解释名称。
-p
选项使其返回发出命令时将执行的磁盘文件的名称。只需使用相同的
bash
算法在搜索PATH
中按给定名称搜索可执行文件。如果有人在路径中放置同名的可执行文件,则这两个选项都将返回 true。 如果考虑安全性,您应该更加小心地从脚本调用命令。
了解您正在运行的内容可能是谨慎的做法。
当然,我还可以实现一个名为
exim
的 shell 脚本,它将在-bV
上返回上述输入; 以及背景中的混乱事物——你的偏执程度是多少?Specifically to check for 'exim', execute
On my Cygwin it gives an output like,
From the 'exim' manual on 'exim -bV',
Comparing with the
type
andwhich
checks.type is a shell builtin command. It indicates how a name will be interpreted by the shell if used as a command. The
-p
option causes it to return the name of the disk file that would be executed if the command was issued.which simply searches for an executable by the given name in the search
PATH
using the samebash
algorithm.Either of these will return true if someone puts an executable file called by the same name in the path. You should be more careful about invoking commands from a script, if security is a concern.
It may be prudent to know what you are running.
Of course, I can also implement a shell script called
exim
that will return the above input on-bV
; and mess-up things in the background -- what is your level of paranoia?您可以使用“which”命令。
它会返回程序的位置,如果不存在则什么也不返回。
You can use the 'which' command.
It will return you the location of the program or nothing if not present.
为了减轻 nik 带来的安全问题,您可以根据预期的位置列表检查可执行文件的位置:
To alleviate the security concerns that nik brought up you can check the location of the executable against an expected list of locations: