小编PJ *_*aki的帖子

通过外壳脚本拒绝对猫的权限

我在〜/ bin / rclone_sync_ACD.log中的日志文件的shell脚本中运行cat时遇到问题。这是shell脚本中的这一行:

RESULT=cat $LOGFILE | tail -1
Run Code Online (Sandbox Code Playgroud)

但是当运行脚本时,我得到:

./rclone_sync: line 63: /Users/pjburnhill/bin/rclone_sync_ACD.log: Permission denied
Run Code Online (Sandbox Code Playgroud)

在终端中,如果输入cat $LOGFILE | tail -1,它将提供正确的输出。

脚本需要具有什么权限才能访问并打印正确的行?

谢谢,PJ

macos bash shell terminal permission-denied

1
推荐指数
1
解决办法
1720
查看次数

Grep问题与shell脚本中的if语句有关

我在shell脚本if语句中有tail&问题grep。如果我tail -5 mylog.log | grep -c "Transferred: 0"在shell中运行,它将按预期运行,但是在此shell脚本中,如果if语句:

# Parse log for results
if [ tail -1 "$LOGFILE" | grep -c "Failed" ] ; then
        RESULT=$(tail -1 "$LOGFILE")
elif [ tail -5 "$LOGFILE" | grep -c "Transferred:            0" ] ; then
        RESULT=""
else
        RESULT=$(tail -5 "$LOGFILE")
fi
Run Code Online (Sandbox Code Playgroud)

我懂了

... [: missing `]'
grep: ]: No such file or directory
Run Code Online (Sandbox Code Playgroud)

对于两个grep行。

显然,关闭]被视为grep的一部分(因此丢失),但是我使用的是正确的空格,所以我不知道发生了什么?我在这里做错了什么?

谢谢,PJ

bash shell grep if-statement tail

0
推荐指数
1
解决办法
3312
查看次数

标签 统计

bash ×2

shell ×2

grep ×1

if-statement ×1

macos ×1

permission-denied ×1

tail ×1

terminal ×1