0

I am trying to run this:

ssh $server_name@$host_IP "for wal in $server_wal_archive_dir/*
    do
            fileD=$(ssh $server_name@$host_IP stat -c %y \"\$wal\" | awk \'{print \$1,\$2}\')

            fileDate=$(date --date=\"$fileD\" +%s)

            if [ $currentDate -gt $fileDate ]
            then
                     ssh $server_name@$host_IP rm $wal
            fi
    done"

But it shows me this message:

awk: '{print
awk: ^ invalid char ''' in expression
stat: cannot stat `': No such file or directory
date: invalid date`""'

I know date error is because no value in $fileD

I have tried to figure it out escaping the single quotes but no luck, what is my mistake?

Thanks in advance

David

Davico
  • 93
  • 1
  • 5
  • 1
    Why wouldn't you just create this as a script on the remote server? – miken32 Feb 18 '16 at 17:15
  • 1
    Wait, why are you connecting to a server and then telling the server to connect back to itself twice? – miken32 Feb 18 '16 at 17:16
  • 2
    For anything more than a simple one-liner, you are better off writing a script copy to the remote server, rather than trying to separate which expansions need to happen locally and which need to happen remotely. – chepner Feb 18 '16 at 17:18
  • I need to collect some files from server to store them safe in another server, I can not install anything in the remote server, I use ssh twice because the first ssh it is only used in the "for" and the second one is to stat command. – Davico Feb 18 '16 at 17:26
  • Yes, but `ssh localhost stat` offers no advantage over just `stat`; in fact, it is hugely wasteful as well as error-prone. – tripleee Feb 18 '16 at 17:55

0 Answers0