Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.
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

How can I pass a path to variable and how I can pass it to the command and execute it?

This is my bash file, if any one can convert it:

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
share|improve this question

1 Answer 1

up vote 1 down vote accepted

create 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}

make executable:

chmod +x backup_script.sh

run:

backup_script.sh /etc/

To debug, change

scp -r $1 ${BACKUP_SERVER_USERNAME}@${BACKUP_SERVER_NAME}:${COPY_FILE_TO_WINDOWS}

to

echo "scp -r $1 ${BACKUP_SERVER_USERNAME}@${BACKUP_SERVER_NAME}:${COPY_FILE_TO_WINDOWS}"

or run:

set -x

share|improve this answer
    
it is dosen't work the following error appear :- ssh: name: host/servname not known –  Mohammad AL-Rawabdeh Oct 6 '10 at 15:07
    
the following result appear :- scp -r hi.txt @: –  Mohammad AL-Rawabdeh Oct 6 '10 at 15:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.