Reputation: 141
What I am try to do is to send file via a sftp using a shell script. I try connecting to a first IP and if this connection fail, I try another one.
Problem is, I can't seem to catch the sftp status.
Here is what I have tried:
#!/bin/bash
sftp -oIdentityFile=path_to_private_key USER@IP1:PATH <<EOF
if [[ $? -eq 0 ]]; then
put myfile
ls
quit
else
echo "ERROR"
fi
EOF
do you have any idea how to makes something like that work:
sftp IP1
if(success){
put file
quit
}
else{
sftp IP2
if(success2){
put file
quit
}
else{
echo "Error"
}
}
Thanks
Upvotes: 0
Views: 3501
Reputation: 141
Found a way to do what I wanted. The problem was as I suspected around the "EOF / if"
Here's what I found :
#!/bin/bash
sftp -oIdentityFile=path_to_private_key USER@$IP1:PATH <<-EOF1
put myfile
quit
EOF1
if [[ $? -ne 0 ]]; then
sftp -oIdentityFile=path_to_private_key USER@$IP2:PATH <<-EOF2
put myfile
quit
-EOF2
if [[ $? -ne 0 ]]; then
echo "ERROR"
fi
fi
Hope it will help anyone who had this problem
Upvotes: 2