首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将此powershell脚本转换为bin/sh脚本?

如何将此powershell脚本转换为bin/sh脚本?
EN

Stack Overflow用户
提问于 2020-10-23 15:12:07
回答 2查看 186关注 0票数 2

如何转换此脚本:

代码语言:javascript
复制
NET USE \\65.161.3.129\someFolder\test /u:somedomain\user myPassword123!
robocopy . \\65.161.3.129\someFolder\test /s
NET USE \\65.161.3.129\someFolder\test /d

或具有参数:

代码语言:javascript
复制
Param($mypath)
NET USE $mypath /u:somedomain\user myPassword123!
robocopy . $mypath /s
NET USE $mypath /d

如何制作类似于linux /bin/sh的脚本?我想将文件复制到某个网络位置(windows共享文件夹)。windows服务器上没有scp,我不能安装任何东西。

EN

Stack Overflow用户

回答已采纳

发布于 2020-10-23 17:50:53

在Linux上,您需要以下内容(在Ubuntu18.04上验证,尽管没有使用Windows域帐户):

  • 先决条件:必须安装cifsutil包,下面的脚本确保了这一点(它按需调用sudo apt-get install cifs-utils )。

  • 选择一个(临时)挂载点(一个可以访问共享文件的本地目录)。

  • 使用mount.cifs实用工具挂载您的共享,而umount稍后使用umount卸载(删除)它。

  • 使用cp -R复制目录层次结构.

注意:

  • sudo (管理)权限是必需的;脚本将提示输入一个密码,该密码通常被缓存几分钟。

代码语言:javascript
复制
#!/bin/sh

# The SMB file-share path given as an argument.
local mypath=$1 

# Choose a (temporary) mount-point dir.
local mountpoint="/tmp/mp_$$"

# Prerequisite:
# Make sure that cifs-utils are installed.
which mount.cifs >/dev/null || sudo apt-get install cifs-utils || exit

# Create the (temporary) mount-point dir.
sudo mkdir -p "$mountpoint" || exit

# Mount the CIFS (SMB) share:
# CAVEAT: OBVIOUSLY, HARD-CODING A PASSWORD IS A SECURITY RISK.
sudo mount.cifs -o user= "user=user,pass=myPassword123!,domain=somedomain" "$mypath" "$mountpoint" || exit

# Perform the copy operation
# Remove the `echo` to actually perform copying.
echo cp -R . "$mountpoint/"

# Unmount the share.
sudo umount "$mountpoint" || exit

# Remove the mount-point dir., if desired
sudo rmdir "$mountpoint"
票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64502680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档