自动 Samba 共享脚本
我有一台运行 Samba 的 Ubuntu 10.04 服务器。
我想编写一个脚本(适用于Linux或Windows计算机),给定该服务器的IP和共享Samba文件夹的路径,可以自动在桌面上创建一个“网络驱动器”图标。两台机器都在本地网络上。
我意识到这对于 linux/windows 来说会有所不同。
有什么建议吗?我只是不知道从哪里开始。谢谢!
I have an Ubuntu 10.04 server running Samba.
I want to write a script (for Linux or Windows computer) that, given the IP of this server and the path of the shared Samba folder, can automatically create a "network drive" icon on the desktop. Both machines are on a local network.
I realize this will be different for linux/windows.
Any suggestions? I'm just not sure where to start. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Windows 计算机,您需要查看
net use
。例如,要将 192.168.0.2 上的共享“Data”映射到 Z:,您可以编写net use Z: \\192.168.0.2\Data
。有很多选项,因此请检查net help use
以获得完整列表。例如,您可能想要查看/persistent
,它会在您每次登录时自动重新创建共享。或者您可以将其放入登录时执行的 .BAT 文件中。
在 Linux 上,我认为您通常必须是 root 才能执行此操作,因为它需要
mount
命令。我知道一些桌面环境(例如 GNOME)可以解决这个问题,但要真正安装它,您需要 root 权限。如果您允许任何人访问,则在挂载点/mnt/Data
挂载相同共享的命令将只是mount //192.168.0.2/Data /mnt/Data
。如果需要登录,则需要添加-o User=YOURUSER
。然后系统将提示您输入密码。(请注意,这需要 CIFS/SMB 驱动程序才能工作)
For Windows machines, you want to look at
net use
. For instance, to map the share "Data" on 192.168.0.2 to Z:, you'd writenet use Z: \\192.168.0.2\Data
. There is a lot of options, so checknet help use
for a complete list. For instance, you might want to look at/persistent
, which would automatically recreate the share every time you log in.Or you could put this in a .BAT file which is executed when logging in.
On linux, I think you'd generally have to be root to do this, as it'd require a
mount
command. I know some desktop environments (such as GNOME) get around this, but to acually mount it you need root. The command to mount the same share at the mountpoint/mnt/Data
would simply bemount //192.168.0.2/Data /mnt/Data
, if you allow anyone access. If you require a logon, you need to add-o User=YOURUSER
. You will then be prompted for a password.(Note that this requires the CIFS/SMB drivers to work)