如何转换此脚本:
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,我不能安装任何东西。
发布于 2020-10-23 17:50:53
在Linux上,您需要以下内容(在Ubuntu18.04上验证,尽管没有使用Windows域帐户):
cifsutil包,下面的脚本确保了这一点(它按需调用sudo apt-get install cifs-utils )。mount.cifs实用工具挂载您的共享,而umount稍后使用umount卸载(删除)它。cp -R复制目录层次结构.注意:
sudo (管理)权限是必需的;脚本将提示输入一个密码,该密码通常被缓存几分钟。#!/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"https://stackoverflow.com/questions/64502680
复制相似问题