Copy and paste of file and folder by script

#!/bin/bash
hostName=$(scutil --get HostName)
installLogName=$hostName-install.log
systemLogName=$hostName-system.log
server=10.96.81.21
folder=/Logs
username=sftp_adm
password=R10grandE@
currentUser=$(stat -f %Su /dev/console)

if [[ ! -d /private/tmp/Logs ]]
then
mkdir /private/tmp/Logs
fi

cp /private/var/log/install.log /tmp/Logs
cp /private/var/log/system.log /tmp/Logs
mv /tmp/Logs/install.log /tmp/Logs/$installLogName
mv /tmp/Logs/system.log /tmp/Logs/$systemLogName
cd /tmp/Logs

chmod 644 /tmp/Logs/$systemLogName

su $currentUser -c "/usr/local/bin/expect<<EOF
spawn /usr/bin/sftp $username@$server
expect \"$username@$server's password:\"
send \"$password\r\"
expect \"sftp>\"
send \"cd $folder\r\"
expect \"sftp>\"
send \"put /tmp/Logs/$systemLogName $systemLogName\r\"
expect \"sftp>\"
send \"put /tmp/Logs/$installLogName $installLogName\r\"
expect \"sftp>\"
send \"put /tmp/Logs/$installLogName $installLogName\r\"
expect \"sftp>\"
send \"quit\"
EOF"
#sftp -n $username@$server <<EOF


exit 0

#expect "$username@$server's password:"
#send "$password\r"expect "Are you sure you want to continue connecting (yes/no/\[fingerprint\])?"
send "yes"



This Script can use to copy and paste file from mac to Linux server after installing TCL on all mac.







Comments

Popular posts from this blog

Creating a Netboot Image by using AutoCasper NBI with Auto DMG

What’s the Difference Between APFS, Mac OS Extended (HFS+), and ExFAT?

Cisco AMP uninstall script