从curl命令控制台输出一些模式文件的grep,并将它们复制到一个目录中



我有一个需求,我需要"grep一些模式文件,并将它们从curl命令控制台输出复制到一个目录中"。

我需要在一个shell脚本中完成所有这些。

例如:

1)$ curl -sk -u username:password https://localhost:port/appname/config/ >/tmp/appname.txt
2)$ `egrep '.truststore$|.keystore$|.jks$|.pem$' /tmp/appname.txt | grep -v pass | sort`

输出:

root4.file=/abc/xyz/app/etc/pvt/old.pem
root3.file=/app/etc/pvt/bbc.pem
root1.File=/app/etc/pvt/abc.pem
db.cluster.trustore=/app/etc/pvt/dbdir/qa-db.jks
someprocess.keystore.path=/app/etc/pvt/qa-key.jks
someprocess.keystore.filename=/homelocation/app/appdir/conf/qa.jks
someprocess..trsustore.filename=/homelocation/app/appdir/conf/qa.jks
newprocess.trustore.filename=/app/etc/dir2/app.jks
otherproces.keystore.filename=/app/etc/new/some.jks
some.tokenfile=/homelocation/apps/etc/somedir/test2.pem.pem
newprocess.filename=qa-key2.jks
appname.keystore.filename=qa.key1.jks
appservice.filename=qa.key3.jks
appname2.filename=qa.new.key4.jks
some3.filename=qa-test_key.jks
some.filename=qa-test_key.jks

3( 现在我需要上面的文件,只有完整的路径需要复制到某个目录"/tmp/newdir">

例如,只需要复制机器上存在的以下文件。

root4.file=/abc/xyz/app/etc/pvt/old.pem
root3.file=/app/etc/pvt/bbc.pem
root1.File=/app/etc/pvt/abc.pem
db.cluster.trustore=/app/etc/pvt/dbdir/qa-db.jks
someprocess.keystore.path=/app/etc/pvt/qa-key.jks
someprocess.keystore.filename=/homelocation/app/appdir/conf/qa.jks
someprocess..trsustore.filename=/homelocation/app/appdir/conf/qa.jks
newprocess.trustore.filename=/app/etc/dir2/app.jks
otherproces.keystore.filename=/app/etc/new/some.jks
some.tokenfile=/homelocation/apps/etc/somedir/test2.pem.pem

这些需要忽略,因为它们没有绝对路径。

newprocess.filename = qa-key2.jks
appname.keystore.filename= qa.key1.jks
appservice.filename = qa.key3.jks
appname2.filename= qa.new.key4.jks
some3.filename =qa-test_key.jks
some.filename= qa-test_key.jks

请帮我处理上述请求。提前谢谢。

如果需要保留目录结构:

cut -d'=' -f2 `command2 output` | grep '^/' | xargs -i cp --parents {} /tmp/newdir/

如果只需要复制文件,只需删除cp中的--parents标志即可。

编辑

需要明确的是,command2 output只是作为第二个命令输出的占位符,因为您似乎正在将输出写入文件。当然,管道仍然可以工作,例如

command2 | cut -d'=' -f2 | grep '^/' | xargs -i cp --parents {} /tmp/newdir/

最新更新