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

How to convert this powershell script to bin/sh script?

如何转换此脚本:

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

或带参数:

Param($mypath)
NET USE $mypath /u:somedomain\user myPassword123!
robocopy . $mypath /s
NET USE $mypath /d

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

如果您使用 linux 风格,curl 实用程序可以处理 SMB(即 \machine\share)路径。示例:

curl -u "domain\username:passwd" smb://server.example.com/share/file.txt

https://curl.haxx.se/docs/manual.html

在 Linux 上,您需要以下内容(已在 Ubuntu 18.04 上验证,尽管不是使用 Windows 帐户) :

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

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

  • 使用 mount.cifs 实用程序装载您的共享,然后 umount 卸载(删除)它。

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

注:

  • sudo 需要(管理)权限;该脚本将提示一次 输入密码,该密码通常会缓存几分钟。
#!/bin/sh

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

# 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"