Solution: Copy Unix to Windows

IT & Software | Operating Systems
Author
Description
Copy logs to windows share (Ubuntu). Shell script.
Attachments
No attachments.
Solutions
#!/bin/bash
# Author  : Rahul Patil
# Date    : Tue Apr  3 15:30:00 IST 2012
# Purpose : Copy logs to windows share (Ubuntu)

# Variables
WIN_PC_IP="192.168.0.13/sharename"   ## IP address with sharename
WIN_USER="rahul"
WIN_PASSWORD="password"
RSYNC=$(which rsync)

# Path of Windows share
DESTPATH="/windows-share"

# Path of Linux file which will be copy to win share
SOURCEPATH="/opt/test/"

LOGFILE="/var/log/copy.log"    

# check samba installed or not if not then install
if [ ! -x /usr/bin/smbclient ]; then
echo "smb-client package not installed"
echo "installing smb-client packge.."
aptitude install samba-client -y
fi

# check mount
if [ ! -d $DESTPATH ]; then
mkdir $DESTPATH
fi

# check winshre mounted or not
mount | grep "$WIN_PC_IP" 1>/dev/null
STATUS=$?
if [ $STATUS -eq 0 ]; then
echo "Windowsshare OK"
else
mount -o username=$WIN_USER,password=$WIN_PASSWORD -t cifs //$WIN_PC_IP $DESTPATH
fi

# check 1
if [ ! -d $DESTPATH ]; then
echo "Creating $DESTPATH"
mkdir $DESTPATH
fi

# Copy files to win share

echo $'\n\n' >> $LOGFILE
$RSYNC -av $SOURCEPATH $DESTPATH 2>&1 >> $LOGFILE
echo 'Completed at: ` date +%d-%b-%y-%T`' >> $LOGFILE 

on November 10th, 2018 (1:11 pm)
What masters said
You must sign in to comment!!
All comments
This solution has not been commented yet.
We use cookies to give you the best possible experience on our site. By continuing to use the site you agree to our use of cookies. Find out more Accept