2

This is my code:

 nb_lignes=`wc -l $1 | cut -d " " -f1`
 for i in $(seq $(($nb_lignes - 1)) )
 do
 machine=`head $1 -n $i | tail -1`
 machine1=`head $1 -n $nb_lignes | tail -1`
 ssh  root@$machine -x " scp /home/file.txt root@$machine1:/home && rm -r /home/file.txt"
 done

I'd like to verify if file.txt exist in such machine before the scp et rm ,Please i ask how can i modify this script ?

Thank you.

1
  • There is a fi in your code, but I don't see any if. Can you please review your code? Commented Oct 20, 2012 at 21:56

1 Answer 1

1

You can use test command: test -f file && scp ...

     ssh  root@$machine -x " test -f /home/file.txt && scp /home/file.txt
root@$machine1:/home && rm -r /home/file.txt"
Sign up to request clarification or add additional context in comments.

11 Comments

Please i have this error at run: Host key verification failed. lost connection have you an idea please ?
That means your ssh connection failed due to authorization issue. Add sshkeys. Here's how to do it: ssh keygen
$machine1 is a variable, i add a quote ?
No, there's nothing with the command/script. ssh fails due to sshkey mismatch/no keys. You have to add the keys and follow that link for instructions on how to add ssh keys.
i have teste with other command ssh root@$machine -x "java..." and it works without pb
|

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.