如何在 cygwin bash 脚本中访问共享驱动器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6483584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:15:15  来源:igfitidea点击:

How do I access a share drive in a cygwin bash script?

bashcygwin

提问by Kelbizzle

#!/bin/bash
"mirror -R //thevault/Shared/Operations/Marketing/test --only-missing -e ;exit"

I'm using lftp to mirror a folder on a share drive. But it fails with "No such file or directory" What's the correct way to write this? and How would I escape a space in the file name. I've tried literally everything.

我正在使用 lftp 镜像共享驱动器上的文件夹。但它失败了“没有这样的文件或目录” 写这个的正确方法是什么?以及如何转义文件名中的空格。我已经尝试了一切。

I've also tried /cygdrive/s/Operations/Marketing/test. This works while I'm logged in and I run the script. But when the task is run while I'm not logged in the log file I get the same "No such file" Error.

我也试过了/cygdrive/s/Operations/Marketing/test。这在我登录并运行脚本时有效。但是当我没有登录日志文件时运行任务时,我得到相同的“没有这样的文件”错误。

采纳答案by Kelbizzle

This seems to be working perfectly while logged out.

这在注销时似乎运行良好。

#!/bin/bash
lftp ftp://username:[email protected] -e "mirror -R //thevault/Share/folder/folder/folder\ with\ spaces/folder/folder --only-missing -e;exit"

It was the escaped spaces in my path. The reason that this didn't work is because when I retyped the path I misspelled share. //thevault/shared <~~ incorrect

这是我路径中的逃逸空间。这不起作用的原因是因为当我重新输入路径时,我拼错了 share。//thevault/shared <~~不正确

#!/bin/bash
"mirror -R //thevault/Shared/folder/folder/test --only-missing -e ;exit"

回答by the_mandrill

I don't think that is support in general in cygwin for UNC pathnames (ie \\server\share) so you'll have to rely on mapping to a network drive and then using /cygdrive/s. To fix the problem with it not working when you aren't logged in, you'll need to call the Windows NETprogram from your script:

我认为 cygwin 通常不支持 UNC 路径名(即\\server\share),因此您必须依赖映射到网络驱动器,然后使用/cygdrive/s. 要解决未登录时它无法运行的问题,您需要NET从脚本中调用 Windows程序:

net use s: \thevault\Shared password /user:myuser 

There may be some security implications to having the password in plaintext, so another possibility is to ensure that the script is running from a user account that has read permission to this server, and then you can omit the password.

使用明文密码可能会有一些安全隐患,因此另一种可能性是确保脚本是从对该服务器具有读取权限的用户帐户运行的,然后您可以省略密码。