vendredi 29 janvier 2016

Bash script - errors: Host Verification failed and unexpected `then'

I wrote a really small script that uploads and moves a file or multiple files from folder to folder, uploads it, checks if the the file is on the server and if yes moves it locally to another folder.

But I am confronted with two error messages. The first one is

Host Verification failed

There is no indication on the line it happens in, but I guess because the file upload does not work, it has to be in line 4. The second error is

unexpected `then'

Suggestions where my mistakes are? I know the code isn't really safe and not well programmed, but in my mind it should work in theory.

#!/bin/bash
sudo find '/path/to/file' -type f -mmin +10 -exec mv '{}' '/path/to_new/folder' \;
sleep 3
sshpass -p 'password' scp /local/path/to_file/Z*.dat user@server:/destination/path/to/folder
sleep 3
Y=$(date +"%Y" | cut -c 4)
hour=$(date -d "1 hour ago" +"Z"$Y"%m%d%H%M")
sshpass -p 'password' ssh user@server 'if[ -f '/path/on/server/to_file/$hour.dat' ]; then echo yes; else echo no; fi'
x=$(echo yes)
z=$(echo no)
if [ "$x" == "yes" ]; then find '/path/to/file' -type f -mmin +10 -exec mv '{}' '/path/to_new/folder' \;;
fi

Thanks, BallerNacken

EDIT: Oh the unexpected `then' is probably due to the missing empty space between the if and the [

Aucun commentaire:

Enregistrer un commentaire