Search code examples
cronsyslog

How to limit Crontab text output.


When cron runs it outputs text from the script that ran and the system calls. Is there a way to limit output?

From This:

From x.site  Tue Jul 31 13:32:45 2018
Return-Path: <a.site>
X-Original-To: a
Delivered-To: a.site
Received: by x.site (Postfix, from userid 1000)
    id 1458910057D; Tue, 31 Jul 2018 13:32:45 -0400 (EDT)
From: "(Cron Daemon)" <a.site>
To: a.site
Subject: Cron <>
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=3737>
X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/1000>
X-Cron-Env: <DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus>
X-Cron-Env: <LC_CTYPE=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/ab10>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=a>
X-Cron-Env: <USER=a>
Message-Id: <[email protected]>
Date: Tue, 31 Jul 2018 13:30:04 -0400 (EDT)


Text from script..

To Something like this:

From x.site  Tue Jul 31 13:32:45 2018
Return-Path: <a.site>
Subject: Cron <>
Content-Type: text/plain; charset=UTF-8
Date: Tue, 31 Jul 2018 13:30:04 -0400 (EDT)


Text from script..

Solution

  • Here is a bash script...

    #!/bin/bash
    awk ' BEGIN {flag=1}
    
    {
    if ($0 ~ /Date:/) { flag=0;
    }
    if ($0 ~ /From/) {  flag=1;
    }
    if (flag==0) {print}
    }
    
    '