0

I have two servers A and B(remote server) ,need to copy files from A to B remote server . before copy i need to remove the files in the remote server depends on my input variable from local server .

For copy command

scp -r file test@host:/home/test/$name1/$name2.pdf

here $name1 and $name2 are the variables getting from local machine , values will vary

above command works fine

For move command

if [ "$name1" = "RAM" ]
then
    ssh test@host 'mv /home/test/$name1/*.pdf /home/test/$name1/backup'

this is not working

can you please suggest me how to archive this.

1
  • if statement is missing an ending fi. I hope it's just a part of your code i.e original code contains an ending fi... Commented May 25, 2015 at 13:23

1 Answer 1

3

You problem is quoting:

if [ "$name1" = "RAM" ]
then
    ssh test@host "mv /home/test/$name1/*.pdf /home/test/$name1/backup"
fi

That is, replace the single quotes with double quotes.

Double quotes allows variable expansion whereas single quotes do not allow any expansion. Note that neither quotes expands the wildcards, so they will be expanded on the remote machine (presumably that's what you need).

If you use double [[ ]] then you don't need to quote the condition variable (even if it contains embedded whitespace):

if [[ $name1 == RAM ]]
then
    ssh test@host "mv /home/test/$name1/*.pdf /home/test/$name1/backup"
fi
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.