17

Every time I use the "at" command, I get this message:

warning: commands will be executed using /bin/sh

What is it trying to warn me about? More importantly, how do I turn the warning off?

raldi
  • 19,496
  • 29
  • 73
  • 85

4 Answers4

13

It serves as a good warning to those of us that don't use bash as our shell, because we we'll forget that a feature that's in our day-to-day shell isn't going to be available when this code is run at the appointed time.

i.e.

username@hostname$ at 23:00     
warning: commands will be executed using /bin/sh
at> rm **/*.pyc
at> <EOT>
job 1 at 2008-10-08 23:00

The use of '**' there is perfectly valid zsh, but not /sbin/sh! It's easy to make these mistakes if you're used to using a different shell, and it's your responsibility to remember to do the right thing.

Jerub
  • 38,558
  • 14
  • 69
  • 90
5

Does the warning have any harmful effect aside from being annoying? The man page doesn't mention any way of turning it off, so I don't think you can stop it from being emitted without rebuilding your at from source.

Now, if you want to just not see it, you can use at [time] 2>/dev/null to send it off to oblivion, but, unfortunately, the at> prompts are printed to STDERR for some reason (a bug, IMO - they really should go to STDOUT), so they're also hidden by this.

It may be possible to work up some shell plumbing which will eliminate the warning without also eating the prompts, but

  1. my attempt at this (at [time] 2>&1 | grep -v warning) doesn't work and
  2. even if you can find a combination that works, it won't be suitable for aliasing (since the time goes in the middle rather than at the end), so you'll need to either type it in full each time you use it or else write a wrapper script around at to handle it.

So, unless it causes actual problems, I'd say you're probably best off just ignoring the warning like the rest of us.

Suuuehgi
  • 2,680
  • 2
  • 20
  • 26
Dave Sherohman
  • 43,013
  • 12
  • 61
  • 98
  • 1
    Ah, nice addition about the STDERR and not the STDOUT. I was Always wondering why the normal redirect didn't work. The side effect of it writing to the STDERR is that it sends an email to the administrator (being me on my local system) which is, as you say, not a harmful effect but yes it is annoying ;-) – Michel Dec 19 '13 at 12:01
  • `stderr` **is in fact correct** for this purpose. POSIX specifies that it be used for all "diagnostic" usage. Status, like information about what input is required when, is diagnostic -- that's why shells write prompts to it, for example -- and that's what you *want* to happen in shell pipelines, so content meant for a human to read to understand what's going on during execution doesn't instead get sucked into the next program in the pipeline. – Charles Duffy Feb 16 '20 at 05:33
3

The source code for at.c (from Debian at 3.1.20-3 version) contains an answer:

/* POSIX.2 allows the shell specified by the user's SHELL environment variable, the login shell from the user's password database entry,
or /bin/sh to be the command interpreter that processes the at-job.
It also alows a warning diagnostic to be printed. Because of the
possible variance, we always output the diagnostic. */

fprintf(stderr, "warning: commands will be executed using /bin/sh\n");

You can work around it with shell redirection:

% echo "echo blah"  | at now+30min 2>&1 | fgrep -v 'warning: commands will be executed using /bin/sh'
job 628 at Fri Mar  8 23:25:00 2019

Or you even create an function for your leisure use (for example for interactive shell in ~/.zshrc or ~/.profile):

at() {
  /usr/bin/at "$@" 2>&1 | fgrep -v 'warning: commands will be executed using /bin/sh'
}

After that, it will not warn your about with that specific warning (while other warning/errors messages will still reach you)

Matija Nalis
  • 620
  • 1
  • 14
  • 23
2

If you wish to get around that message, have 'at' run a script that calls a specified environment, be it ksh, bash, csh, zsh, perl, etc.

addition - see the 'at' man page http://www.rt.com/man/at.1.html for more information.

at and batch read commands from standard input or a specified  file which are to be executed at a later time, using /bin/sh.
warren
  • 28,486
  • 19
  • 80
  • 115