先上配置文件
[data]
serverpath=//192.168.31.245/linux
user=administrator
password=xxxx
localpath=/winshare
shell脚本如下
if [ ! -e ./smbforwin.ini ];then
echo "smbforwin.ini not exist"
exit
fi
#sed -n '2,$p' ./smbforwin.ini
array=("serverpath" "user" "password" "localpath")
n=0
for item in ${array[@]};do
arr[$n]=$(cat ./smbforwin.ini|grep ${item}|awk -F '=' '{print $2}')
echo ${array[$n]}:${arr[$n]}
let n++
done
ip=$(cat ./smbforwin.ini|grep -Po '(\d+\.){3}\d+')
echo ip:${ip}
read -p "pause"
t=`yum list installed|grep samba-client`
if [[ -z $t ]] ; then
echo "samba-client not installed"
yum -y install samba samba-client
sleep 3s
fi
smbclient -L $ip -U ${arr[1]}%${arr[2]} >/dev/null
if [ $? -ne 0 ];then
echo "connect remotehost has wrong!"
exit
fi
if [ ! -e ${arr[3]} ];then
echo "create folder /winshare"
mkdir ${arr[3]}
fi
mount -t cifs -o username="${arr[1]}",password="${arr[2]}" ${arr[0]} ${arr[3]}
cd ${arr[3]}
ls
如图所示,访问成功
?
|