user1735757
user1735757

Reputation: 185

Verifying if a file exist (script shell)

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.

Upvotes: 2

Views: 233

Answers (1)

P.P
P.P

Reputation: 121347

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"

Upvotes: 1

Related Questions