传递变量通过SSH进行-newermt选项查找 [英] pass variable to find via ssh for -newermt option

查看:798
本文介绍了传递变量通过SSH进行-newermt选项查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一定时间范围内从远程服务器(服务器B)与本地服务器(服务器A)上运行脚本复制一组文件。
我使用在找到-newermt选项来指定自己的时间范围。
所以,如果我ssh到远程服务器(服务器B)这个作品:

I am trying to copy a group of files within a certain time range from a remote server(server B) with a script run on a local server(Server A). I'm using the -newermt option in find to specify my time range. So if I ssh to the remote server(server B) this works:

find /appl/backup/monsters/green/y.y.y.y/2016-04-26_08-00-01/jelly/ -newermt "2016-04-26 07:40:00" \! -newermt "2016-04-26 07:50:00"

和我得到的文件的时间列表中指定。

And I get the list of files for the times specified.

不过,如果我尝试从通过ssh在本地服务器(服务器A)involke这样的:

However, If I try to involke this from the local server (server A) via ssh:

#!/bin/bash
#           
CLUSTER="green"
node="x.x.x.x"
STIME="2016-04-26_08-00-01" 
#T1=1461678000
#T2=1461678600
T1="2016-04-26 07:40:00"
T2="2016-04-26 07:50:00"             
ssh user@y.y.y.y find /appl/backup/monsters/${CLUSTER}/${node}/${STIME}/jelly/ -newermt "$T1" \\! -newermt "$T2"
echo $latest_file
echo SCP Completed.
exit

这给了我一个发现错误:

This gives me a find error:

查找:路径必须precede前pression:七时40分00秒。

find: paths must precede expression: 07:40:00

这样看来,用这种方法发现不喜欢的空间2016年4月26日七点40分00秒

So it appears that with this method find does not like the space in "2016-04-26 07:40:00"

我想转换为unixtimestamps避免使用空间,但发现不喜欢那些:

I tried converting to unixtimestamps to avoid using a space but find does not like those:

查找:我无法弄清楚如何跨$ P $`PT 1461678000'作为一个日期或时间

find: I cannot figure out how to interpret `1461678000' as a date or time

我的问题是我需要界定这个或大括号的空格字符,我想了一些东西,但完全摸索周围: - /任何帮助是AP preciated

My question is do I have to delimit the space character for this or curly brackets, I'm trying a few things but totally fumbling around :-/ any help is appreciated.

谢谢!

推荐答案

现在的问题是,你是在本地端,但是不能在远程端报价。

The problem is that you are quoting on the local side but not on the remote side.

您使用的是周围$ T1双引号$ T2正在被拆除运行 SSH 命令,但远程命令则没有引号保护空间从远程shell之前本地shell。

The double quotes you are using around "$T1" and "$T2" are being removed by the local shell before running the ssh command but the remote command then doesn't have the quotes protecting the space from the remote shell.

所以本地shell看到:

So the local shell sees:

[ssh] [user@y.y.y.y] [find] [/appl/backup/monsters/${CLUSTER}/${node}/${STIME}/jelly/] [-newermt] [2016-04-26 07:40:00] [\!] [-newermt] [2016-04-26 07:50:00]

但远程shell看到:

but the remote shell sees:

[ssh] [user@y.y.y.y] [find] [/appl/backup/monsters/${CLUSTER}/${node}/${STIME}/jelly/] [-newermt] [2016-04-26] [07:40:00] [\!] [-newermt] [2016-04-26] [07:50:00]

和这就是问题所在。

的参数 -newermt 被视为 2016年4月26日 07 :40:00 被视为其中找到看到作为路径,因此它给你的路径必须是第一位的的错误流浪的说法。

The argument to -newermt is seen as 2016-04-26 and 07:40:00 is seen as a stray argument which find sees as a path and so it gives you the "paths must come first" error.

您需要加引号,使其通过远程侧,双引号将整个字符串(允许变量扩展本地),然后使用围绕扩大值单引号远程shell。

You need the quotes to make it through to the remote side so double quote the entire string (to allow for variable expansion locally) and then use single quotes around the expanded values for the remote shell.

ssh user@y.y.y.y "find '/appl/backup/monsters/${CLUSTER}/${node}/${STIME}/jelly/' -newermt '$T1' \! -newermt '$T2'"

这篇关于传递变量通过SSH进行-newermt选项查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆