我正在设置一个脚本,该脚本通过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.gz
REC_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文件范围内带有' 的数据。
湖上湖
哈士奇WWW