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"
11
  • Please i have this error at run: Host key verification failed. lost connection have you an idea please ? Commented Oct 22, 2012 at 13:46
  • That means your ssh connection failed due to authorization issue. Add sshkeys. Here's how to do it: ssh keygen
    – P.P
    Commented Oct 22, 2012 at 13:51
  • $machine1 is a variable, i add a quote ? Commented Oct 22, 2012 at 13:52
  • 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.
    – P.P
    Commented Oct 22, 2012 at 13:54
  • i have teste with other command ssh root@$machine -x "java..." and it works without pb Commented Oct 22, 2012 at 13:58

Your Answer

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

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