I'm trying to figure out a way to ssh to a remote file, check whether a file exists, and if it exist ssh back to the first server, execute a command and get done. Here is a snippet of my code so far:
for file_name in $(ls $FILE_DIR/)
do
ssh [email protected]: home/some/directory
'if [ -f $DIRECTORY/$file_name ]
then
ssh [email protected]: home/some/Directory
'scp [email protected]: $DIRECTORY/$file_name $DIRECTORY/$file_name"_"$(date +%Y%m%d%H%M%S)
fi''
scp [email protected] $FILE_DIR/$file_name $DIRECTORY/$file_name
When I execute the script, the connection to the remote server opens up in the command line and the rest of the script doesn't get executed.
Also, is what I'm trying to do valid? Can I ssh within an server that has been accesed through ssh?
sshcommand manually? I think the first time you connect to a server, ssh gives a prompt about RSA fingerprint.