Unix
路徑作為變數
BACKUP_SERVER_NAME="name" BACKUP_SERVER_USERNAME="user" COPY_FILE_TO_WINDOWS="/cygdrive/c/unix_test_copy" scp -r /$1/ $PRIMARY_SERVER_USERNAME@$PRIMARY_SERVER_NAME:$COPY_FILE_TO_WINDOWS
如何將路徑傳遞給變數以及如何將其傳遞給命令並執行它?
這是我的 bash 文件,如果有人可以轉換它:
PRIMARY_SERVER_NAME="error.com.jo" PRIMARY_SERVER_USERNAME="Administrator" BACKUP_SERVER_NAME="V1DEV1.com.jo" BACKUP_SERVER_USERNAME="Administrator" COPY_FILE_TO_WINDOWS="/cygdrive/c/unix_test_copy" SCAN_BATCH_FILE_WINDOWS="c:\\scan.bat" LOG_FILE="/var/log/scan.log" if [ -f "$1" ] then scp -r $1 ${BACKUP_SERVER_USERNAME}@${BACKUP_SERVER_NAME}:${COPY_FILE_TO_WINDOWS}" server_status=$? server_status_on=0 if [$server_status -eq $server_status_on ]; then ssh -l ${BACKUP_SERVER_USERNAME}@${PRIMARY_SERVER_NAME} 'cmd /c ${SCAN_BATCH_FILE_WINDOWS} {$COPY_FILE_TO_WINDOWS}\'$1' else scp -r $1 ${BACKUP_SERVER_USERNAME}@${BACKUP_SERVER_NAME}:${COPY_FILE_TO_WINDOWS} ssh -l ${BACKUP_SERVER_USERNAME} ${BACKUP_SERVER_NAME} 'cmd /c ${SCAN_BATCH_FILE_WINDOWS}${COPY_FILE_TO_WINDOWS}\'$1'' fi error_code=$?" echo "[$(date +%c)] $1 error_code = $?" >> ${LOG_FILE} exit $error_code" else echo "[$(date +%c)] $1 error_code = 5" >> ${LOG_FILE} exit 5 fi
創建backup_script.sh
#!/bin/bash BACKUP_SERVER_NAME="name" BACKUP_SERVER_USERNAME="user" COPY_FILE_TO_WINDOWS="/cygdrive/c/unix_test_copy" scp -r $1 ${BACKUP_SERVER_USERNAME}@${BACKUP_SERVER_NAME}:${COPY_FILE_TO_WINDOWS}
使可執行:
chmod +x backup_script.sh
跑:
backup_script.sh /etc/
調試,改變
scp -r $1 ${BACKUP_SERVER_USERNAME}@${BACKUP_SERVER_NAME}:${COPY_FILE_TO_WINDOWS}
到
echo "scp -r $1 ${BACKUP_SERVER_USERNAME}@${BACKUP_SERVER_NAME}:${COPY_FILE_TO_WINDOWS}"
或執行:
set -x