【发布时间】:2019-11-10 03:45:56
【问题描述】:
我正在设置一个脚本,它使用read 命令获取一些用户数据。使用这些数据,我需要搜索文件范围,然后进行一些过滤。
是这样的,
Enter fromtime
read fromtime
Enter totime
read totime
Enter the ID
read id
最初我通过 SSH 连接到服务器,然后我有一个目录,路径为 cd home/report/records 的记录,我有:
-
REC_201901020345.gz(yyyymmddhhmm) REC_201901120405.gzREC_201903142543.gz
等等。
这些文件有数据以及$id。
当用户输入 $fromtime 和 $totime 时,格式为 yyyymmddhh 。在这里,我需要转到该文件范围,然后转到 grep 以获取 $id 并显示。例如:
如果$fromtime 是2019010103 并且$totime 是2019031425。我只需要转到REC_201901020345.gz、REC_201901120405.gz、REC_201903142543.gz 的特定文件范围并执行grep 以查找用户输入的id。
我已经尝试过使用if 条件,但它似乎不起作用。我是编写这样的脚本的新手。当我在这里描述所有内容时,可能会有错误。对不起。
source config.sh
Enter fromtime
read fromtime
Enter totime
read totime
Enter the ID
read id
ssh $user@$ip
cd /home/report/records
# <-- need to know what to add here as described here, to navigate to the
# <-- specific range $fromtime-$totime. Then the command to find id will be
zfgrep $id *.gz
结果应该只是id指定范围内.gz文件的数据。
【问题讨论】:
-
您的目录中有多少个文件?数百,一些视图数千甚至更多?你能发布你的代码吗,到目前为止?
-
文件将是
REC_yyyymmddhhmm.gz除了日期之外没有其他变化吗? -
@Edvin 格式为 yyyymmddhh。