本文介绍了获取外壳输出的最后一行作为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用exiftool处理shell脚本,以自动更改某些文件夹中包含的图片上的一些exif标签,并且我想使用输出在作业完成时在NAS(QNAP)上获得通知.

I am working on a shell script with exiftool to automatically change some exif tags on pictures contained in a certain folder and I would like to use the output to get a notification on my NAS (a QNAP) when the job is completed.

一切正常,但是-通知系统截断消息时-我只想接收所需的信息,即shell输出的最后一行,例如:

Everything works already, but - as the notification system truncates the message - I would like to receive just the information I need, i.e. the last line of the shell output, which is for example the following:

Warning: [minor] Entries in IFD0 were out of sequence. Fixed. - 2015-07-12 15.41.06.jpg
 4512 files failed condition
  177 image files updated

问题是当前我仅收到以下通知:

The problem is that currently I only receive the following notification:

我想得到的是:

脚本如下:

#!/bin/sh
# exiftool script for 2002 problem
dir="/share/Multimedia/Camera"
cd "$dir"
FOLDER="$(printf '%s\n' "${PWD##*/}")"
OUTPUT="$(exiftool -overwrite_original -r '-CreateDate<DateTimeOriginal' -if '$CreateDate eq "2002:12:08 12:00:00"' -if '$DateTimeOriginal ne $CreateDate' *.[Jj][Pp][Gg])"
/sbin/notice_log_tool -a "Exiftool cronjob completed on ${FOLDER}: ${OUTPUT}" --severity=5
exit 0

要使用$ OUTPUT变量,请使用|尾-1,但可能我犯了一些基本错误,并且收到类似以下内容的信息:

To do that I played with the $OUTPUT variable using | tail -1, but probably I make some basic errors and I receive something like:

如何以正确的方式做到这一点?谢谢

How to do it in the right way? Thanks

推荐答案

将尾巴放在捕获对象的内部.

Put the tail inside the capturing parens.

OUTPUT=$(exif ... | tail -1)

这里不需要双引号.我猜你尝试过

You don't need the double quotes here. I'm guessing that youtried

OUTPUT="$(exif ...) | tail -1"

这篇关于获取外壳输出的最后一行作为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:28