Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Apr 2019 17:40:42 -0400 (EDT)
From:      Walter Cramer <wfc@mintsol.com>
To:        Software Info <softwareinfojam@gmail.com>
Cc:        Jonathan Chen <jonc@chen.org.nz>, "freebsd-stable@freebsd.org" <freebsd-stable@freebsd.org>
Subject:   RE: Crontab Question
Message-ID:  <20190410172638.C14867@mulder.mintsol.com>
In-Reply-To: <5cae5cc3.1c69fb81.15e0.dbd1@mx.google.com>
References:  <5cae4e6f.1c69fb81.95785.62bf@mx.google.com> <CAJuc1zNRcG5WaZ4weC=TNLuXCfT=oxMtismm%2B6apWXEtJZhH3A@mail.gmail.com> <5cae5cc3.1c69fb81.15e0.dbd1@mx.google.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 10 Apr 2019, Software Info wrote:

> OK. So although the script is located in my home directory, it doesn=E2=
=80=99t=20
> start there?  Sorry but I don=E2=80=99t quite understand. Could you expla=
in a=20
> little further please?

Both 'cp' and 'ls' are located in /bin.  But if I run the 'ls' command in=
=20
/root, 'ls' can't find 'cp' (unless I tell it where to look) - even though=
=20
/bin *is* in my PATH -

server7:/root # ls cp
ls: cp: No such file or directory
server7:/root # ls /bin/cp
/bin/cp

Where the system looks for *commands*, to execute, is different from where=
=20
it looks for other files, which those commands use.  The latter is=20
generally only the current directory (unless you tell it otherwise).=20
When cron runs a script as root, "current directory" will be /root.

BUT - for security and other reasons, it would be better to have cron run=
=20
your script as you (not root), and as '/home/me/myscript' (instead of=20
adding your home directory to PATH in /etc/crontab).

-Walter
From owner-freebsd-stable@freebsd.org  Wed Apr 10 21:43:37 2019
Return-Path: <owner-freebsd-stable@freebsd.org>
Delivered-To: freebsd-stable@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 59767156E564
 for <freebsd-stable@mailman.ysv.freebsd.org>;
 Wed, 10 Apr 2019 21:43:37 +0000 (UTC)
 (envelope-from jonc@chen.org.nz)
Received: from mail-vs1-xe2b.google.com (mail-vs1-xe2b.google.com
 [IPv6:2607:f8b0:4864:20::e2b])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id 6DE9A8CF85
 for <freebsd-stable@freebsd.org>; Wed, 10 Apr 2019 21:43:36 +0000 (UTC)
 (envelope-from jonc@chen.org.nz)
Received: by mail-vs1-xe2b.google.com with SMTP id g187so2265307vsc.8
 for <freebsd-stable@freebsd.org>; Wed, 10 Apr 2019 14:43:36 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=chen-org-nz.20150623.gappssmtp.com; s=20150623;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc:content-transfer-encoding;
 bh=st5EF6Toj4oaftpjqMp60Jwg7uVMLOwxgM2q05BzpoY=;
 b=BHbrJEJoZ2erusel0A94uhdfWRf+4Ud4FvxI0vJd3v3sYHo1hxG8k8L/5MnirVY9b0
 WQV5xZvXUVpbGsNQp82sIhh9Wa0budkXfF5RIVKMbXQSxeIvBKYZ3kLvWFIUOUOkfqb1
 h3tY+plgS6zseUnJCZ8eLTONmv8tA5vnYfCoY8lSogzRQ4wTMYXV4OHlqwdqtUldGHnt
 /ZujFsP+2OIjUTVdXtBa2CQacSd3URCEmqnSTUd/LVfyWAFIGpFNO8SvDLBFh/m7vtmA
 F9dbTzmdcvUJFRw1WJW8JRSIkU7TuiDcpwL3WB08MELkoAFBhALVASZoEKPQEOqQLGhT
 IKKQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc:content-transfer-encoding;
 bh=st5EF6Toj4oaftpjqMp60Jwg7uVMLOwxgM2q05BzpoY=;
 b=EYv/2kJhGjT5+bMo3bnlDfyDk/uYJezO5FnoRv76zN6kFbHi01NeDPLnni23ma02Lu
 +KmkyNWupKerCth8HsBd52jieJH452TsopF536+qm8p/Q0QnzHHPxkQMMWSuDwixGiWu
 WfEdS0g9/yZsXnGudaJT0+v+X5HUVdn5pMz7cs8S5JDLQtyWLPMXiHQ6x/Gx02PkeF+I
 oZfq0ohW9EvurH5I3VG6Dfo4wQxomdQwQ2sHMsvmG0X3erHTlcZoL1gSqGfl21sKFCMp
 k5aJ7kTQJ+lt8NjRz8Vp/PMmQ1hj0/EGOVpVyz6P+Ov0Z5Urfbq0Up0J41BUE5aKCWmn
 8+eA==
X-Gm-Message-State: APjAAAUFA7vgcv9DYy9CzZIYObCgSMoPO2KMW6eOecylj5Zc/UA7v2Jl
 GFDCnomMApxhbj4xxst/cd9+TQaFwagJjUUP5v3mEw==
X-Google-Smtp-Source: APXvYqwTYBfq8nIPn/8p3EZvyUA+PSOidDp4kKxr+5TcVNRlp0C31mrjo3ztD8+lFb3cQeZptGp3Obd3l2Sjl1NKdcY=
X-Received: by 2002:a67:844d:: with SMTP id g74mr26014840vsd.40.1554932615491; 
 Wed, 10 Apr 2019 14:43:35 -0700 (PDT)
MIME-Version: 1.0
References: <5cae4e6f.1c69fb81.95785.62bf@mx.google.com>
 <CAJuc1zNRcG5WaZ4weC=TNLuXCfT=oxMtismm+6apWXEtJZhH3A@mail.gmail.com>
 <5cae5cc3.1c69fb81.15e0.dbd1@mx.google.com>
 <CAJuc1zNdGBRWcdjwdOw+U7bqChRcFPqnKpS-kskhnpHvN=2d+A@mail.gmail.com>
 <5cae6179.1c69fb81.12661.3a08@mx.google.com>
In-Reply-To: <5cae6179.1c69fb81.12661.3a08@mx.google.com>
From: Jonathan Chen <jonc@chen.org.nz>
Date: Thu, 11 Apr 2019 09:43:19 +1200
Message-ID: <CAJuc1zPPQxd71aTkeHGhMcNMF7CEx9Evd4Q1FrVx_Ah0PjRA5Q@mail.gmail.com>
Subject: Re: Crontab Question
To: Software Info <softwareinfojam@gmail.com>
Cc: "freebsd-stable@freebsd.org" <freebsd-stable@freebsd.org>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Rspamd-Queue-Id: 6DE9A8CF85
X-Spamd-Bar: ------
Authentication-Results: mx1.freebsd.org;
 dkim=pass header.d=chen-org-nz.20150623.gappssmtp.com header.s=20150623
 header.b=BHbrJEJo
X-Spamd-Result: default: False [-6.20 / 15.00]; ARC_NA(0.00)[];
 TO_DN_EQ_ADDR_SOME(0.00)[];
 R_DKIM_ALLOW(-0.20)[chen-org-nz.20150623.gappssmtp.com:s=20150623];
 NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[];
 TO_DN_SOME(0.00)[]; NEURAL_HAM_SHORT(-0.91)[-0.913,0];
 NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain];
 PREVIOUSLY_DELIVERED(0.00)[freebsd-stable@freebsd.org];
 DMARC_NA(0.00)[chen.org.nz]; TO_MATCH_ENVRCPT_SOME(0.00)[];
 DKIM_TRACE(0.00)[chen-org-nz.20150623.gappssmtp.com:+];
 MX_GOOD(-0.01)[cached: alt1.aspmx.l.google.com];
 RCPT_COUNT_TWO(0.00)[2];
 RCVD_IN_DNSWL_NONE(0.00)[b.2.e.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org
 : 127.0.5.0]; R_SPF_NA(0.00)[]; FREEMAIL_TO(0.00)[gmail.com];
 FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+];
 RCVD_TLS_LAST(0.00)[];
 ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US];
 RCVD_COUNT_TWO(0.00)[2];
 IP_SCORE(-2.98)[ip: (-9.68), ipnet: 2607:f8b0::/32(-2.96), asn: 15169(-2.19),
 country: US(-0.06)]
X-BeenThere: freebsd-stable@freebsd.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Production branch of FreeBSD source code <freebsd-stable.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-stable>, 
 <mailto:freebsd-stable-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-stable/>;
List-Post: <mailto:freebsd-stable@freebsd.org>
List-Help: <mailto:freebsd-stable-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-stable>,
 <mailto:freebsd-stable-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 10 Apr 2019 21:43:37 -0000

On Thu, 11 Apr 2019 at 09:34, Software Info <softwareinfojam@gmail.com> wro=
te:
>
> I see. I had however copied the output of env to the etc/crontab PATH lin=
e. Wouldn=E2=80=99t that care for an environment issue though?

When I say "environment", I mean it in the generic sense; including
working-directory.

However, best practise is to keep /etc/crontab as minimal as possible,
and to set up environ(7) within the invoked script-file.
Security-wise, you should just keep PATH in /etc/crontab to the
standard, and invoke your script with:
* * * * * user /path/to/my/script

This is especially important when running as root.

Cheers.
--=20
Jonathan Chen <jonc@chen.org.nz>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20190410172638.C14867>