Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Those who don't understand Linux are doomed to reinvent it, poorly. -- unidentified source


devel / comp.unix.shell / Crontab How to direct it from stdin to stdout?

SubjectAuthor
* Crontab How to direct it from stdin to stdout?Chris Roberts
+* Re: Crontab How to direct it from stdin to stdout?Kenny McCormack
|`* Re: Crontab How to direct it from stdin to stdout?Spiros Bousbouras
| +- Re: Crontab How to direct it from stdin to stdout?Spiros Bousbouras
| +- DIY MTA (Was: Crontab How to direct it from stdin to stdout?)Kenny McCormack
| `* Re: Crontab How to direct it from stdin to stdout?Keith Thompson
|  +* Re: Crontab How to direct it from stdin to stdout?William Unruh
|  |`* Re: Crontab How to direct it from stdin to stdout?Spiros Bousbouras
|  | `* Re: Crontab How to direct it from stdin to stdout?Chris Roberts
|  |  `* Re: Crontab How to direct it from stdin to stdout?Chris Roberts
|  |   +- Re: Crontab How to direct it from stdin to stdout?William Unruh
|  |   `- Re: Crontab How to direct it from stdin to stdout?Keith Thompson
|  `- Re: Crontab How to direct it from stdin to stdout?Spiros Bousbouras
+- Re: Crontab How to direct it from stdin to stdout?Kaz Kylheku
+- Re: Crontab How to direct it from stdin to stdout?Lew Pitcher
+- Re: Crontab How to direct it from stdin to stdout?Dan Espen
+- Re: Crontab How to direct it from stdin to stdout?Randal L. Schwartz
`- Re: Crontab How to direct it from stdin to stdout?Janis Papanagnou

1
Crontab How to direct it from stdin to stdout?

<32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3836&group=comp.unix.shell#3836

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ad4:5b81:: with SMTP id 1mr26924149qvp.12.1621864163290; Mon, 24 May 2021 06:49:23 -0700 (PDT)
X-Received: by 2002:ad4:5223:: with SMTP id r3mr25767895qvq.0.1621864163104; Mon, 24 May 2021 06:49:23 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Mon, 24 May 2021 06:49:22 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=4.79.195.162; posting-account=tSqayAoAAADEbq2bVxu4ODgY7tmW5dUx
NNTP-Posting-Host: 4.79.195.162
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
Subject: Crontab How to direct it from stdin to stdout?
From: thecjg...@gmail.com (Chris Roberts)
Injection-Date: Mon, 24 May 2021 13:49:23 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 35
 by: Chris Roberts - Mon, 24 May 2021 13:49 UTC

crontab issue:
Hi perhaps someone would have some ideas?
I want to run my script via crontab,
Problem: via crontab it successfully creates tmp1.txt and directs output to that file, it can't seem to bring the output back to tty terminal again.

Question: How do I get crontab to behave like when I just run the file straight?

The below file:
1: Creates the file "tmp1.txt" (Works both, whether I run the script straight OR Crontab).
2: It will echo 2 lines to the tty screen. (Only works when running straight. Crontab won't echo the second line).

#MY SCRIPT:
#!/usr/bin/bash
echo Script Started.
exec &> /mnt/c/temp/tmp1.txt #send all output to tmp1.txt
echo this
echo that
exec > "$(tty)" #start sending output to the tty screen again
echo But can you read me now?
------
#RUNNING IT STRAIGHT FROM PROMPT :
crzzy1:/mnt/c/Tech/Scripts/Crontabs$ /usr/bin/bash -c /mnt/c/unixscripts/tmpscript2
Script Started.
But can you read me now?
----
crzzy1:/mnt/c/Tech/Scripts/Crontabs$ crontab -l
* * * * * /usr/bin/bash -c /mnt/c/unixscripts/tmpscript2 > /dev/tty4

#CRONTAB AFTER 3 MINUTES.
crzzy1:/mnt/c/Tech/Scripts/Crontabs$ Script Started.
Script Started.
Script Started.
---

Thanks,
crzzy1

Re: Crontab How to direct it from stdin to stdout?

<s8gc39$19bk7$1@news.xmission.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3837&group=comp.unix.shell#3837

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Date: Mon, 24 May 2021 14:09:45 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <s8gc39$19bk7$1@news.xmission.com>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
Injection-Date: Mon, 24 May 2021 14:09:45 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1355399"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Mon, 24 May 2021 14:09 UTC

In article <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>,
Chris Roberts <thecjguy1@gmail.com> wrote:
>crontab issue:
>Hi perhaps someone would have some ideas?
>I want to run my script via crontab,
>Problem: via crontab it successfully creates tmp1.txt and directs output to that
>file, it can't seem to bring the output back to tty terminal again.
>
>Question: How do I get crontab to behave like when I just run the file straight?

The basic answer is that there is no "tty terminal" when running in crontab.
The "tty" command will return "not a tty" (you can verify this by typing,
at a regular terminal prompt: tty < /dev/null).

Now, as to your basic question/problem: What you need to do is forget
about directing stuff to a tty (since there is no tty to direct it to) and
instead rely on the fact that the CRON daemon will email you the "results"
of your cronjob. Here, by "results", we mean the combined output of
"stdout" and "stderr".

Now, the thing is, on a regular, full-blown, fully configured, fully
functional Unix system, this all will "just work". You would have already
worked out that the output you seek is in your email inbox. But, I'm going
to guess here that you are running this on some kind of minimal Unix
system, where there is no MTA (*) setup/configured. In that case, you need
to setup an MTA - which can be either an easy, 2 minute task, or a several
days/weeks task, depending on how you choose to go about it.

I'm going to leave it there for now; please respond further if you need
further help.

(*) MTA = "Mail Transfer Agent"

--
> No, I haven't, that's why I'm asking questions. If you won't help me,
> why don't you just go find your lost manhood elsewhere.

CLC in a nutshell.

Re: Crontab How to direct it from stdin to stdout?

<20210524070939.554@kylheku.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3838&group=comp.unix.shell#3838

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 563-365-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Date: Mon, 24 May 2021 14:14:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <20210524070939.554@kylheku.com>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
Injection-Date: Mon, 24 May 2021 14:14:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="33972978d8ac13cd843334b558695e72";
logging-data="4896"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19o9ZE/SWBVv5+JM3RDg3Lqj7LRG1KDJ58="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:+fsx5/BE9hsJ7dBKMvDvqeJ8x6o=
 by: Kaz Kylheku - Mon, 24 May 2021 14:14 UTC

On 2021-05-24, Chris Roberts <thecjguy1@gmail.com> wrote:
> crontab issue:
> Hi perhaps someone would have some ideas?
> I want to run my script via crontab,
> Problem: via crontab it successfully creates tmp1.txt and directs output to that file, it can't seem to bring the output back to tty terminal again.
>
> Question: How do I get crontab to behave like when I just run the file
> straight?

I can't comprehend what you're asking. Cron runs as a service. It
executes commands according to their crontab schedule.

This happens outside of any TTY session. The commands run even if you
are not logged into the system at all.

> The below file:
> 1: Creates the file "tmp1.txt" (Works both, whether I run the script straight OR Crontab).
> 2: It will echo 2 lines to the tty screen. (Only works when running straight. Crontab won't echo the second line).

The output of cron jobs is e-mailed to their user. Check your inbox.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Crontab How to direct it from stdin to stdout?

<s8gcin$4mu$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3839&group=comp.unix.shell#3839

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Date: Mon, 24 May 2021 14:17:59 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 20
Message-ID: <s8gcin$4mu$1@dont-email.me>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 24 May 2021 14:17:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f7b16cd821f79fc99bccc8fafb52de25";
logging-data="4830"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18t8Im653lNA5msMr9Qyw0/dTyQdEy4QRo="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:m/FhvJGHRz/OEezrYeTn6YvlbZ8=
 by: Lew Pitcher - Mon, 24 May 2021 14:17 UTC

On Mon, 24 May 2021 06:49:22 -0700, Chris Roberts wrote:

> crontab issue:
> Hi perhaps someone would have some ideas?
> I want to run my script via crontab,
> Problem: via crontab it successfully creates tmp1.txt and directs output to that file, it can't seem to bring the output back to tty terminal again.

Bye and large, a process run from crontab /does not/ have a tty attached to stdin or stdout.
So, unless you are running a unique form of crond, your script will /never/ find a terminal
behind $(tty)

> Question: How do I get crontab to behave like when I just run the file straight?

By either assigning a specific terminal device to stdout as part of your script, or by not
running it through crond.

[snip]
--
Lew Pitcher
"In Skills, We Trust"

Re: Crontab How to direct it from stdin to stdout?

<s8gev0$krh$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3840&group=comp.unix.shell#3840

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dan1es...@gmail.com (Dan Espen)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Date: Mon, 24 May 2021 10:58:40 -0400
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <s8gev0$krh$1@dont-email.me>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0737b5eb34357bd1016a1a3b6afbdbd3";
logging-data="21361"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hbqPpgWnJB6HTy6TJFG6ayL1XXEGwsiE="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:m0lG5Pil/Ziz5wT0GwXhy+9dQds=
 by: Dan Espen - Mon, 24 May 2021 14:58 UTC

Chris Roberts <thecjguy1@gmail.com> writes:

> crontab issue: Hi perhaps someone would have some ideas? I want to
> run my script via crontab, Problem: via crontab it successfully
> creates tmp1.txt and directs output to that file, it can't seem to
> bring the output back to tty terminal again.

You should tell us what problem you are trying to solve.

As other posters have pointed out cron has no associated TTY.
If your objective is to be able to see the script output, the email
cron sends should do the job. If you would like something more in your
face, perhaps you want the script to use notify-send.

--
Dan Espen

Re: Crontab How to direct it from stdin to stdout?

<86cztg4011.fsf@red.stonehenge.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3841&group=comp.unix.shell#3841

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!ecngs!feeder2.ecngs.de!178.20.174.213.MISMATCH!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx02.iad.POSTED!not-for-mail
From: mer...@stonehenge.com (Randal L. Schwartz)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
x-mayan-date: Long count = 13.0.8.9.16; tzolkin = 12 Cib; haab = 14 Zip
Message-ID: <86cztg4011.fsf@red.stonehenge.com>
Organization: Stonehenge Consulting Services; Portland, Oregon, USA
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (berkeley-unix)
Cancel-Lock: sha1:lv3Lb4Mb4zGc9D05cUuOuVFVNfY=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 49
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Mon, 24 May 2021 15:43:05 UTC
Date: Mon, 24 May 2021 08:35:54 -0700
X-Received-Bytes: 2412
 by: Randal L. Schwartz - Mon, 24 May 2021 15:35 UTC

>>>>> "Chris" == Chris Roberts <thecjguy1@gmail.com> writes:

Chris> #MY SCRIPT:
Chris> #!/usr/bin/bash
Chris> echo Script Started.
Chris> exec &> /mnt/c/temp/tmp1.txt #send all output to tmp1.txt
Chris> echo this
Chris> echo that
Chris> exec > "$(tty)" #start sending output to the tty screen again
Chris> echo But can you read me now?

I would write this as:

#!/usr/bin/bash
echo Script Started.
(
echo this
echo that
) &> /mnt/c/temp/tmp1.txt #send all output to tmp1.txt
echo But can you read me now?

Of course, you'll then get an email every time the script runs, without
the contents of the stuff sent to tmp1.txt, just the first and last
lines. I would write this as:

#!/usr/bin/bash
echo Script Started.
(
echo this
echo that
) 2>&1 | tee /mnt/c/temp/tmp1.txt #send all output to tmp1.txt
echo But can you read me now?

That way the contents are still in your email, but also in the file.

Also I did a double-take on &>. Must be a bash-ism. The classic way is
as I did, using 2>&1 to make stderr point at what stdout points at,
which will be the pipe to the input of tee. For a file, that'd look
like:

) >some_file 2>&1

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Dart/Flutter consulting, Technical writing, Comedy, etc. etc.
Still trying to think of something clever for the fourth line of this .sig

Re: Crontab How to direct it from stdin to stdout?

<rM1TWvAw8O3jHtf1o@bongo-ra.co>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3842&group=comp.unix.shell#3842

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.gegeweb.eu!gegeweb.org!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx39.ams4.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Message-ID: <rM1TWvAw8O3jHtf1o@bongo-ra.co>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com> <s8gc39$19bk7$1@news.xmission.com>
In-Reply-To: <s8gc39$19bk7$1@news.xmission.com>
X-Organisation: Weyland-Yutani
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 57
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Mon, 24 May 2021 17:14:30 UTC
Organization: virginmedia.com
Date: Mon, 24 May 2021 17:14:30 GMT
X-Received-Bytes: 3415
 by: Spiros Bousbouras - Mon, 24 May 2021 17:14 UTC

On Mon, 24 May 2021 14:09:45 -0000 (UTC)
gazelle@shell.xmission.com (Kenny McCormack) wrote:
> In article <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>,
> Chris Roberts <thecjguy1@gmail.com> wrote:
> >crontab issue:
> >Hi perhaps someone would have some ideas?
> >I want to run my script via crontab,
> >Problem: via crontab it successfully creates tmp1.txt and directs output to that
> >file, it can't seem to bring the output back to tty terminal again.
> >
> >Question: How do I get crontab to behave like when I just run the file straight?
>
> The basic answer is that there is no "tty terminal" when running in crontab.
> The "tty" command will return "not a tty" (you can verify this by typing,
> at a regular terminal prompt: tty < /dev/null).
>
> Now, as to your basic question/problem: What you need to do is forget
> about directing stuff to a tty (since there is no tty to direct it to) and
> instead rely on the fact that the CRON daemon will email you the "results"
> of your cronjob. Here, by "results", we mean the combined output of
> "stdout" and "stderr".
>
> Now, the thing is, on a regular, full-blown, fully configured, fully
> functional Unix system, this all will "just work". You would have already
> worked out that the output you seek is in your email inbox. But, I'm going
> to guess here that you are running this on some kind of minimal Unix
> system, where there is no MTA (*) setup/configured. In that case, you need
> to setup an MTA - which can be either an easy, 2 minute task, or a several
> days/weeks task, depending on how you choose to go about it.

For what the opening poster asks setting up a MTA would be way overkill. All
that is needed is a script like

#!/bin/sh
{ printf 'Email received at %s\n\n' "`date`"
cat
printf '\n\n======================\n'
} >> /home/username/emails
# End of script

, make it executable and inform cron that the above script is the "mail
agent". I don't remember how one achieves the latter task (creating a
symbolic link /usr/bin/mail which points to the script should work) and I
also don't remember if cron submits the email to be sent as the stdin of
the "mail agent". If yes , then the above cat command will do the job ; if
not then perhaps the script must process its argument(s) and something like
cat "$1" is needed. But the basic idea is valid.

> I'm going to leave it there for now; please respond further if you need
> further help.
>
> (*) MTA = "Mail Transfer Agent"

--
Is anyone besides me ready for a good pandemic!?
www.imdb.com/review/rw2735248

Re: Crontab How to direct it from stdin to stdout?

<sss1TWvAw8O3jHtf1@bongo-ra.co>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3843&group=comp.unix.shell#3843

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!feeder5.feed.usenet.farm!feeder1.feed.usenet.farm!feed.usenet.farm!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx36.ams4.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Message-ID: <sss1TWvAw8O3jHtf1@bongo-ra.co>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com> <s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co>
In-Reply-To: <rM1TWvAw8O3jHtf1o@bongo-ra.co>
X-Organisation: Weyland-Yutani
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 59
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Mon, 24 May 2021 17:18:52 UTC
Organization: virginmedia.com
Date: Mon, 24 May 2021 17:18:52 GMT
X-Received-Bytes: 3553
 by: Spiros Bousbouras - Mon, 24 May 2021 17:18 UTC

On Mon, 24 May 2021 17:14:30 GMT
Spiros Bousbouras <spibou@gmail.com> wrote:
> On Mon, 24 May 2021 14:09:45 -0000 (UTC)
> gazelle@shell.xmission.com (Kenny McCormack) wrote:
> > In article <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>,
> > Chris Roberts <thecjguy1@gmail.com> wrote:
> > >crontab issue:
> > >Hi perhaps someone would have some ideas?
> > >I want to run my script via crontab,
> > >Problem: via crontab it successfully creates tmp1.txt and directs output to that
> > >file, it can't seem to bring the output back to tty terminal again.
> > >
> > >Question: How do I get crontab to behave like when I just run the file straight?
> >
> > The basic answer is that there is no "tty terminal" when running in crontab.
> > The "tty" command will return "not a tty" (you can verify this by typing,
> > at a regular terminal prompt: tty < /dev/null).
> >
> > Now, as to your basic question/problem: What you need to do is forget
> > about directing stuff to a tty (since there is no tty to direct it to) and
> > instead rely on the fact that the CRON daemon will email you the "results"
> > of your cronjob. Here, by "results", we mean the combined output of
> > "stdout" and "stderr".
> >
> > Now, the thing is, on a regular, full-blown, fully configured, fully
> > functional Unix system, this all will "just work". You would have already
> > worked out that the output you seek is in your email inbox. But, I'm going
> > to guess here that you are running this on some kind of minimal Unix
> > system, where there is no MTA (*) setup/configured. In that case, you need
> > to setup an MTA - which can be either an easy, 2 minute task, or a several
> > days/weeks task, depending on how you choose to go about it.
>
> For what the opening poster asks setting up a MTA would be way overkill. All
> that is needed is a script like
>
> #!/bin/sh
> {
> printf 'Email received at %s\n\n' "`date`"
> cat
> printf '\n\n======================\n'
> } >> /home/username/emails
> # End of script
>

This approach is advisable if there is only one user of the system who
is also the administrator.

> , make it executable and inform cron that the above script is the "mail
> agent". I don't remember how one achieves the latter task (creating a
> symbolic link /usr/bin/mail which points to the script should work) and I
> also don't remember if cron submits the email to be sent as the stdin of
> the "mail agent". If yes , then the above cat command will do the job ; if
> not then perhaps the script must process its argument(s) and something like
> cat "$1" is needed. But the basic idea is valid.
>
> > I'm going to leave it there for now; please respond further if you need
> > further help.
> >
> > (*) MTA = "Mail Transfer Agent"

DIY MTA (Was: Crontab How to direct it from stdin to stdout?)

<s8gnpv$19hqt$1@news.xmission.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3844&group=comp.unix.shell#3844

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: DIY MTA (Was: Crontab How to direct it from stdin to stdout?)
Date: Mon, 24 May 2021 17:29:35 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <s8gnpv$19hqt$1@news.xmission.com>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com> <s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co>
Injection-Date: Mon, 24 May 2021 17:29:35 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1361757"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Mon, 24 May 2021 17:29 UTC

In article <rM1TWvAw8O3jHtf1o@bongo-ra.co>,
Spiros Bousbouras <spibou@gmail.com> wrote:
....
>For what the opening poster asks setting up a MTA would be way overkill. All
>that is needed is a script like
>
>#!/bin/sh
>{
> printf 'Email received at %s\n\n' "`date`"
> cat
> printf '\n\n======================\n'
>} >> /home/username/emails
># End of script

Of course. I do that all the time. That's what I meant by "you can do it
in 2 minutes".

And all you have to do is put that script at /usr/sbin/sendmail
(That's all; no configuration of cron is needed to make it use it)

Another neat trick is to install procmail (apt install procmail), then make
/usr/sbin/sendmail be a link to /usr/bin/procmail. Then, assuming you are
comfortable with and proficient in procmail. you can do whatever you want
via the .procmailrc file.

--
There are a lot of Wisconsin farmers right now who, despite having
themselves voted for Trump, are now wishing that their state's electors
had had the good sense to vote for the other candidate - thereby saving
them from their current predicament.

Re: Crontab How to direct it from stdin to stdout?

<87a6oj4yay.fsf@nosuchdomain.example.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3845&group=comp.unix.shell#3845

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Date: Mon, 24 May 2021 14:27:49 -0700
Organization: None to speak of
Lines: 33
Message-ID: <87a6oj4yay.fsf@nosuchdomain.example.com>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
<s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="515a578b1fbda6d2e69cf5c5ac94ed10";
logging-data="26275"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/T3r/3RO+ruXQ1ZCtQzyk/"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
Cancel-Lock: sha1:7/4kiOK35X9N6udWyV7vghpq/K8=
sha1:BEaj0P6flpdqYag7bLgZ/PYw9gA=
 by: Keith Thompson - Mon, 24 May 2021 21:27 UTC

Spiros Bousbouras <spibou@gmail.com> writes:
[...]
> For what the opening poster asks setting up a MTA would be way overkill. All
> that is needed is a script like
>
> #!/bin/sh
> {
> printf 'Email received at %s\n\n' "`date`"
> cat
> printf '\n\n======================\n'
> } >> /home/username/emails
> # End of script
>
> , make it executable and inform cron that the above script is the "mail
> agent". I don't remember how one achieves the latter task (creating a
> symbolic link /usr/bin/mail which points to the script should work) and I
> also don't remember if cron submits the email to be sent as the stdin of
> the "mail agent". If yes , then the above cat command will do the job ; if
> not then perhaps the script must process its argument(s) and something like
> cat "$1" is needed. But the basic idea is valid.

Why would you need to set up an MTA, even a trivial fake one?

If a cron job writes to stdout or stderr, cron sends the output to the
user via email. If you want the output in a file, simply have the
cron job write to the file.

0 8 * * * echo Good morning from cron >> $HOME/cron.out

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Re: Crontab How to direct it from stdin to stdout?

<s8he3b$114$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3846&group=comp.unix.shell#3846

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: unr...@invalid.ca (William Unruh)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Date: Mon, 24 May 2021 23:50:03 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <s8he3b$114$1@dont-email.me>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
<s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co>
<87a6oj4yay.fsf@nosuchdomain.example.com>
Injection-Date: Mon, 24 May 2021 23:50:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2ec23c039ac09c0c16fc3a68d69ae348";
logging-data="1060"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qY7xerystRVXN/JyBB/Wu"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:B13h3m6kI5LuOYrWa0KuNT9YA7g=
 by: William Unruh - Mon, 24 May 2021 23:50 UTC

On 2021-05-24, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Spiros Bousbouras <spibou@gmail.com> writes:
> [...]
>> For what the opening poster asks setting up a MTA would be way overkill. All
>> that is needed is a script like
>>
>> #!/bin/sh
>> {
>> printf 'Email received at %s\n\n' "`date`"
>> cat
>> printf '\n\n======================\n'
>> } >> /home/username/emails
>> # End of script
>>
>> , make it executable and inform cron that the above script is the "mail
>> agent". I don't remember how one achieves the latter task (creating a
>> symbolic link /usr/bin/mail which points to the script should work) and I
>> also don't remember if cron submits the email to be sent as the stdin of
>> the "mail agent". If yes , then the above cat command will do the job ; if
>> not then perhaps the script must process its argument(s) and something like
>> cat "$1" is needed. But the basic idea is valid.
>
> Why would you need to set up an MTA, even a trivial fake one?

The question is is there anything running on the computer that will
transfer that email that cron sends to the inbox of the person running
the cron job.

But then again, the cron job is running on the same computer that would
receive the mail I assume, so the user can simply look at the file
into which the output is placed. Why an email?
If the system is different than the one the user usually runs, then one
would need an MTA to transfer the mail from the one on which the cron
job runs to the one on which the user usually sits.
>
> If a cron job writes to stdout or stderr, cron sends the output to the
> user via email. If you want the output in a file, simply have the
> cron job write to the file.
>
> 0 8 * * * echo Good morning from cron >> $HOME/cron.out
>

Re: Crontab How to direct it from stdin to stdout?

<s8iiu9$9h$1@news-1.m-online.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3847&group=comp.unix.shell#3847

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Date: Tue, 25 May 2021 12:18:49 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 53
Message-ID: <s8iiu9$9h$1@news-1.m-online.net>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
NNTP-Posting-Host: 2001:a61:252a:da01:3512:8fc3:e3a3:aead
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1621937929 305 2001:a61:252a:da01:3512:8fc3:e3a3:aead (25 May 2021 10:18:49 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Tue, 25 May 2021 10:18:49 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
 by: Janis Papanagnou - Tue, 25 May 2021 10:18 UTC

On 24.05.2021 15:49, Chris Roberts wrote:
> crontab issue:
> Hi perhaps someone would have some ideas?
> I want to run my script via crontab,
> Problem: via crontab it successfully creates tmp1.txt and directs output to that file, it can't seem to bring the output back to tty terminal again.
>
> Question: How do I get crontab to behave like when I just run the file straight?

The cron jobs have no terminal assigned (you get the output per email).

If you want the output on a terminal you have to define which terminal.
For example

your_job | tee output.txt /dev/pts/3

redirect your jobs data (in addition to creating the email) to a file
output.txt and to the terminal with the given identifier /dev/pts/3.
You can of course omit any the the output target channels shown only
as example.

Janis

> The below file:
> 1: Creates the file "tmp1.txt" (Works both, whether I run the script straight OR Crontab).
> 2: It will echo 2 lines to the tty screen. (Only works when running straight. Crontab won't echo the second line).
>
> #MY SCRIPT:
> #!/usr/bin/bash
> echo Script Started.
> exec &> /mnt/c/temp/tmp1.txt #send all output to tmp1.txt
> echo this
> echo that
> exec > "$(tty)" #start sending output to the tty screen again
> echo But can you read me now?
> ------
> #RUNNING IT STRAIGHT FROM PROMPT :
> crzzy1:/mnt/c/Tech/Scripts/Crontabs$ /usr/bin/bash -c /mnt/c/unixscripts/tmpscript2
> Script Started.
> But can you read me now?
> ----
> crzzy1:/mnt/c/Tech/Scripts/Crontabs$ crontab -l
> * * * * * /usr/bin/bash -c /mnt/c/unixscripts/tmpscript2 > /dev/tty4
>
> #CRONTAB AFTER 3 MINUTES.
> crzzy1:/mnt/c/Tech/Scripts/Crontabs$ Script Started.
> Script Started.
> Script Started.
> ---
>
> Thanks,
> crzzy1
>

Re: Crontab How to direct it from stdin to stdout?

<7XX22SxPSqtRqNAIi@bongo-ra.co>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3848&group=comp.unix.shell#3848

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!feeder.usenetexpress.com!tr2.eu1.usenetexpress.com!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx40.ams4.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Message-ID: <7XX22SxPSqtRqNAIi@bongo-ra.co>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com> <s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co> <87a6oj4yay.fsf@nosuchdomain.example.com>
In-Reply-To: <87a6oj4yay.fsf@nosuchdomain.example.com>
X-Organisation: Weyland-Yutani
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 32
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Tue, 25 May 2021 23:05:01 UTC
Organization: virginmedia.com
Date: Tue, 25 May 2021 23:05:01 GMT
X-Received-Bytes: 2160
 by: Spiros Bousbouras - Tue, 25 May 2021 23:05 UTC

On Mon, 24 May 2021 14:27:49 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Spiros Bousbouras <spibou@gmail.com> writes:
> [...]
> > For what the opening poster asks setting up a MTA would be way overkill. All
> > that is needed is a script like
> >
> > #!/bin/sh
> > {
> > printf 'Email received at %s\n\n' "`date`"
> > cat
> > printf '\n\n======================\n'
> > } >> /home/username/emails
> > # End of script
> >
> > , make it executable and inform cron that the above script is the "mail
> > agent". I don't remember how one achieves the latter task (creating a
> > symbolic link /usr/bin/mail which points to the script should work) and I
> > also don't remember if cron submits the email to be sent as the stdin of
> > the "mail agent". If yes , then the above cat command will do the job ; if
> > not then perhaps the script must process its argument(s) and something like
> > cat "$1" is needed. But the basic idea is valid.
>
> Why would you need to set up an MTA, even a trivial fake one?
>
> If a cron job writes to stdout or stderr, cron sends the output to the
> user via email. If you want the output in a file, simply have the
> cron job write to the file.
>
> 0 8 * * * echo Good morning from cron >> $HOME/cron.out

If one only wants the output of one script then yes , your solution is simpler.

Re: Crontab How to direct it from stdin to stdout?

<t5SxPSqtRqNAIi@bongo-ra.co>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3849&group=comp.unix.shell#3849

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!news.uzoreto.com!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx08.ams4.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Message-ID: <t5SxPSqtRqNAIi@bongo-ra.co>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com> <s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co>
<87a6oj4yay.fsf@nosuchdomain.example.com> <s8he3b$114$1@dont-email.me>
In-Reply-To: <s8he3b$114$1@dont-email.me>
X-Organisation: Weyland-Yutani
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 60
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Tue, 25 May 2021 23:32:26 UTC
Organization: virginmedia.com
Date: Tue, 25 May 2021 23:32:26 GMT
X-Received-Bytes: 3465
 by: Spiros Bousbouras - Tue, 25 May 2021 23:32 UTC

On Mon, 24 May 2021 23:50:03 -0000 (UTC)
William Unruh <unruh@invalid.ca> wrote:
> On 2021-05-24, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> > Spiros Bousbouras <spibou@gmail.com> writes:
> > [...]
> >> For what the opening poster asks setting up a MTA would be way overkill. All
> >> that is needed is a script like
> >>
> >> #!/bin/sh
> >> {
> >> printf 'Email received at %s\n\n' "`date`"
> >> cat
> >> printf '\n\n======================\n'
> >> } >> /home/username/emails
> >> # End of script
> >>
> >> , make it executable and inform cron that the above script is the "mail
> >> agent". I don't remember how one achieves the latter task (creating a
> >> symbolic link /usr/bin/mail which points to the script should work) and I
> >> also don't remember if cron submits the email to be sent as the stdin of
> >> the "mail agent". If yes , then the above cat command will do the job ; if
> >> not then perhaps the script must process its argument(s) and something like
> >> cat "$1" is needed. But the basic idea is valid.
> >
> > Why would you need to set up an MTA, even a trivial fake one?
>
> The question is is there anything running on the computer that will
> transfer that email that cron sends to the inbox of the person running
> the cron job.

Or indeed , is there an inbox at all ?

> But then again, the cron job is running on the same computer that would
> receive the mail I assume,

From the code given in the opening post that seems a safe assumption.

> so the user can simply look at the file
> into which the output is placed. Why an email?
> If the system is different than the one the user usually runs, then one
> would need an MTA to transfer the mail from the one on which the cron
> job runs to the one on which the user usually sits.

And a mail server on the other computer to receive it. Again , this seems
overkill if the only goal is to see the output of a cron job running on
one computer of a local network on another. Something like NFS and having
the cron job write to a file mounted over the network would be simpler.

> > If a cron job writes to stdout or stderr, cron sends the output to the
> > user via email. If you want the output in a file, simply have the
> > cron job write to the file.
> >
> > 0 8 * * * echo Good morning from cron >> $HOME/cron.out
> >

--
We offer to spell check marketing emails, and a call recording service for marketing
calls, for £50+VAT which you can request simply by sending a marketing email to any
of our email addresses or making a marketing call to one of our numbers.
https://www.aa.net.uk/etc/contact/

Re: Crontab How to direct it from stdin to stdout?

<28b53599-d23c-4110-8dc1-8b494fd40a46n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3870&group=comp.unix.shell#3870

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:6699:: with SMTP id d25mr3513200qtp.326.1622127564927;
Thu, 27 May 2021 07:59:24 -0700 (PDT)
X-Received: by 2002:ae9:c110:: with SMTP id z16mr3952607qki.30.1622127564734;
Thu, 27 May 2021 07:59:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 27 May 2021 07:59:24 -0700 (PDT)
In-Reply-To: <t5SxPSqtRqNAIi@bongo-ra.co>
Injection-Info: google-groups.googlegroups.com; posting-host=23.30.126.234; posting-account=tSqayAoAAADEbq2bVxu4ODgY7tmW5dUx
NNTP-Posting-Host: 23.30.126.234
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
<s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co>
<87a6oj4yay.fsf@nosuchdomain.example.com> <s8he3b$114$1@dont-email.me> <t5SxPSqtRqNAIi@bongo-ra.co>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <28b53599-d23c-4110-8dc1-8b494fd40a46n@googlegroups.com>
Subject: Re: Crontab How to direct it from stdin to stdout?
From: thecjg...@gmail.com (Chris Roberts)
Injection-Date: Thu, 27 May 2021 14:59:24 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 135
 by: Chris Roberts - Thu, 27 May 2021 14:59 UTC

On Tuesday, May 25, 2021 at 7:32:33 PM UTC-4, Spiros Bousbouras wrote:
> On Mon, 24 May 2021 23:50:03 -0000 (UTC)
> William Unruh <un...@invalid.ca> wrote:
> > On 2021-05-24, Keith Thompson <Keith.S.T...@gmail.com> wrote:
> > > Spiros Bousbouras <spi...@gmail.com> writes:
> > > [...]
> > >> For what the opening poster asks setting up a MTA would be way overkill. All
> > >> that is needed is a script like
> > >>
> > >> #!/bin/sh
> > >> {
> > >> printf 'Email received at %s\n\n' "`date`"
> > >> cat
> > >> printf '\n\n======================\n'
> > >> } >> /home/username/emails
> > >> # End of script
> > >>
> > >> , make it executable and inform cron that the above script is the "mail
> > >> agent". I don't remember how one achieves the latter task (creating a
> > >> symbolic link /usr/bin/mail which points to the script should work) and I
> > >> also don't remember if cron submits the email to be sent as the stdin of
> > >> the "mail agent". If yes , then the above cat command will do the job ; if
> > >> not then perhaps the script must process its argument(s) and something like
> > >> cat "$1" is needed. But the basic idea is valid.
> > >
> > > Why would you need to set up an MTA, even a trivial fake one?
> >
> > The question is is there anything running on the computer that will
> > transfer that email that cron sends to the inbox of the person running
> > the cron job.
> Or indeed , is there an inbox at all ?
> > But then again, the cron job is running on the same computer that would
> > receive the mail I assume,
> From the code given in the opening post that seems a safe assumption.
> > so the user can simply look at the file
> > into which the output is placed. Why an email?
> > If the system is different than the one the user usually runs, then one
> > would need an MTA to transfer the mail from the one on which the cron
> > job runs to the one on which the user usually sits.
> And a mail server on the other computer to receive it. Again , this seems
> overkill if the only goal is to see the output of a cron job running on
> one computer of a local network on another. Something like NFS and having
> the cron job write to a file mounted over the network would be simpler.
> > > If a cron job writes to stdout or stderr, cron sends the output to the
> > > user via email. If you want the output in a file, simply have the
> > > cron job write to the file.
> > >
> > > 0 8 * * * echo Good morning from cron >> $HOME/cron.out
> > >
> --
> We offer to spell check marketing emails, and a call recording service for marketing
> calls, for £50+VAT which you can request simply by sending a marketing email to any
> of our email addresses or making a marketing call to one of our numbers.
> https://www.aa.net.uk/etc/contact/

I thank all of you again, Could not have done it without your help.
I wish I could post my actual script, which is much longer, but there are work sensitivities.
the "echo" portion is more of a script that goes out and scrapes a lot of data.
While at work I use it to monitor a bunch of stuff every couple of hours.
It will email me (Yes on the same PC) on a cron job so I can compare the emails and just be aware of changes and what it all looks like now.
I also have a second one I can run on demand with no email, just screen output.
I didn't know about shellcheck, but it really is a great tool and speeds things along for my simple code.

In the future, I may further enhance it, and then get it onto a VM that is always up.

######
#!/usr/bin/bash
echo Script Started.
( set -x
echo this
echo 100 this
echo that
echo 100 that
) &> /mnt/c/temp/logfile.txt
( echo But can you read me now?
n=0
c=0
while read -r line;
do
n=$((n+1))
w[$n]=$line
if [[ $line =~ .*100.* ]]
then
c=$((c+1))
echo "${w[$((n))]}"
fi
done < /mnt/c/temp/tmp1.txt
echo "You have $c lines with 100"
) > /mnt/c/temp/pallout.txt
set +x
#swaks --to user@email.com --from "user@email.com" --h-Subject: pall-out --server MAIL.email.com --body /mnt/c/temp/pallout.txt
echo "now send it also to the TTY"
cat /mnt/c/temp/pallout.txt
echo done.
####
#OUTPUT: Note it will email this to me if I just let the swaks command fly.
# tmp
Script Started.
now send it also to the TTY
But can you read me now?
100 this
100 that
"You have 2 lines with 100"
done.
######
thanks,
crzzy1

Re: Crontab How to direct it from stdin to stdout?

<d71d1f96-c4b4-4863-9b1a-bc9da8c62858n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3995&group=comp.unix.shell#3995

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:12c7:: with SMTP id s7mr17568497qvv.60.1624998286167; Tue, 29 Jun 2021 13:24:46 -0700 (PDT)
X-Received: by 2002:a05:622a:164d:: with SMTP id y13mr28495864qtj.244.1624998285837; Tue, 29 Jun 2021 13:24:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 29 Jun 2021 13:24:45 -0700 (PDT)
In-Reply-To: <28b53599-d23c-4110-8dc1-8b494fd40a46n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=4.79.195.162; posting-account=tSqayAoAAADEbq2bVxu4ODgY7tmW5dUx
NNTP-Posting-Host: 4.79.195.162
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com> <s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co> <87a6oj4yay.fsf@nosuchdomain.example.com> <s8he3b$114$1@dont-email.me> <t5SxPSqtRqNAIi@bongo-ra.co> <28b53599-d23c-4110-8dc1-8b494fd40a46n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d71d1f96-c4b4-4863-9b1a-bc9da8c62858n@googlegroups.com>
Subject: Re: Crontab How to direct it from stdin to stdout?
From: thecjg...@gmail.com (Chris Roberts)
Injection-Date: Tue, 29 Jun 2021 20:24:46 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 161
 by: Chris Roberts - Tue, 29 Jun 2021 20:24 UTC

On Thursday, May 27, 2021 at 10:59:28 AM UTC-4, Chris Roberts wrote:
> On Tuesday, May 25, 2021 at 7:32:33 PM UTC-4, Spiros Bousbouras wrote:
> > On Mon, 24 May 2021 23:50:03 -0000 (UTC)
> > William Unruh <un...@invalid.ca> wrote:
> > > On 2021-05-24, Keith Thompson <Keith.S.T...@gmail.com> wrote:
> > > > Spiros Bousbouras <spi...@gmail.com> writes:
> > > > [...]
> > > >> For what the opening poster asks setting up a MTA would be way overkill. All
> > > >> that is needed is a script like
> > > >>
> > > >> #!/bin/sh
> > > >> {
> > > >> printf 'Email received at %s\n\n' "`date`"
> > > >> cat
> > > >> printf '\n\n======================\n'
> > > >> } >> /home/username/emails
> > > >> # End of script
> > > >>
> > > >> , make it executable and inform cron that the above script is the "mail
> > > >> agent". I don't remember how one achieves the latter task (creating a
> > > >> symbolic link /usr/bin/mail which points to the script should work) and I
> > > >> also don't remember if cron submits the email to be sent as the stdin of
> > > >> the "mail agent". If yes , then the above cat command will do the job ; if
> > > >> not then perhaps the script must process its argument(s) and something like
> > > >> cat "$1" is needed. But the basic idea is valid.
> > > >
> > > > Why would you need to set up an MTA, even a trivial fake one?
> > >
> > > The question is is there anything running on the computer that will
> > > transfer that email that cron sends to the inbox of the person running
> > > the cron job.
> > Or indeed , is there an inbox at all ?
> > > But then again, the cron job is running on the same computer that would
> > > receive the mail I assume,
> > From the code given in the opening post that seems a safe assumption.
> > > so the user can simply look at the file
> > > into which the output is placed. Why an email?
> > > If the system is different than the one the user usually runs, then one
> > > would need an MTA to transfer the mail from the one on which the cron
> > > job runs to the one on which the user usually sits.
> > And a mail server on the other computer to receive it. Again , this seems
> > overkill if the only goal is to see the output of a cron job running on
> > one computer of a local network on another. Something like NFS and having
> > the cron job write to a file mounted over the network would be simpler.
> > > > If a cron job writes to stdout or stderr, cron sends the output to the
> > > > user via email. If you want the output in a file, simply have the
> > > > cron job write to the file.
> > > >
> > > > 0 8 * * * echo Good morning from cron >> $HOME/cron.out
> > > >
> > --
> > We offer to spell check marketing emails, and a call recording service for marketing
> > calls, for £50+VAT which you can request simply by sending a marketing email to any
> > of our email addresses or making a marketing call to one of our numbers..
> > https://www.aa.net.uk/etc/contact/
> I thank all of you again, Could not have done it without your help.
> I wish I could post my actual script, which is much longer, but there are work sensitivities.
> the "echo" portion is more of a script that goes out and scrapes a lot of data.
> While at work I use it to monitor a bunch of stuff every couple of hours.
> It will email me (Yes on the same PC) on a cron job so I can compare the emails and just be aware of changes and what it all looks like now.
> I also have a second one I can run on demand with no email, just screen output.
> I didn't know about shellcheck, but it really is a great tool and speeds things along for my simple code.
>
> In the future, I may further enhance it, and then get it onto a VM that is always up.
>
> ######
> #!/usr/bin/bash
> echo Script Started.
> (
> set -x
> echo this
> echo 100 this
> echo that
> echo 100 that
> ) &> /mnt/c/temp/logfile.txt
> (
> echo But can you read me now?
> n=0
> c=0
> while read -r line;
> do
> n=$((n+1))
> w[$n]=$line
> if [[ $line =~ .*100.* ]]
> then
> c=$((c+1))
> echo "${w[$((n))]}"
> fi
> done < /mnt/c/temp/tmp1.txt
> echo "You have $c lines with 100"
> ) > /mnt/c/temp/pallout.txt
> set +x
> #swaks --to us...@email.com --from "us...@email.com" --h-Subject: pall-out --server MAIL.email.com --body /mnt/c/temp/pallout.txt
> echo "now send it also to the TTY"
> cat /mnt/c/temp/pallout.txt
> echo done.
> ####
> #OUTPUT: Note it will email this to me if I just let the swaks command fly.
> # tmp
> Script Started.
> now send it also to the TTY
> But can you read me now?
> 100 this
> 100 that
> "You have 2 lines with 100"
> done.
> ######
> thanks,
> crzzy1

I really appreciate everyone's help so much.
I have this working really well.
one nagging question:
I can run my script stand alone fine, but once crontab spits anything out to terminal.
it won't return to the original prompt.
ie:
* * * * * echo "HI" > /dev/tty3
RETURNS:
myhost$ HI

(It hangs on a blank line and just sits there, I must hit enter to get out.).
Any way I can get it to look like so:
myhost$ HI
myhost$

Thanks

Re: Crontab How to direct it from stdin to stdout?

<sbg3f2$7ni$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3996&group=comp.unix.shell#3996

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: unr...@invalid.ca (William Unruh)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Date: Tue, 29 Jun 2021 21:31:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <sbg3f2$7ni$1@dont-email.me>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
<s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co>
<87a6oj4yay.fsf@nosuchdomain.example.com> <s8he3b$114$1@dont-email.me>
<t5SxPSqtRqNAIi@bongo-ra.co>
<28b53599-d23c-4110-8dc1-8b494fd40a46n@googlegroups.com>
<d71d1f96-c4b4-4863-9b1a-bc9da8c62858n@googlegroups.com>
Injection-Date: Tue, 29 Jun 2021 21:31:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ceeadf10bae032fbf31788f74c1d4937";
logging-data="7922"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZikYiH2g555NAusPvClF0"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Ut0cDOcQJG7shX5QsMUiNuEWEso=
 by: William Unruh - Tue, 29 Jun 2021 21:31 UTC

On 2021-06-29, Chris Roberts <thecjguy1@gmail.com> wrote:
>
> I really appreciate everyone's help so much.
> I have this working really well.
> one nagging question:
> I can run my script stand alone fine, but once crontab spits anything out to terminal.
> it won't return to the original prompt.
> ie:
> * * * * * echo "HI" > /dev/tty3
> RETURNS:
> myhost$ HI

I am completely unclear as to what you were doing here.

What did you run to get the above? crontab is not a command line
command. It is a file which the daemon cron running in the background
runs.
>
> (It hangs on a blank line and just sits there, I must hit enter to get out.).

What hangs?

> Any way I can get it to look like so:
> myhost$ HI
> myhost$
>
> Thanks
>

Re: Crontab How to direct it from stdin to stdout?

<87eecktkoz.fsf@nosuchdomain.example.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3997&group=comp.unix.shell#3997

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: Crontab How to direct it from stdin to stdout?
Date: Tue, 29 Jun 2021 14:39:08 -0700
Organization: None to speak of
Lines: 52
Message-ID: <87eecktkoz.fsf@nosuchdomain.example.com>
References: <32d79aec-3844-476a-a85b-18ed4ed52d1fn@googlegroups.com>
<s8gc39$19bk7$1@news.xmission.com> <rM1TWvAw8O3jHtf1o@bongo-ra.co>
<87a6oj4yay.fsf@nosuchdomain.example.com> <s8he3b$114$1@dont-email.me>
<t5SxPSqtRqNAIi@bongo-ra.co>
<28b53599-d23c-4110-8dc1-8b494fd40a46n@googlegroups.com>
<d71d1f96-c4b4-4863-9b1a-bc9da8c62858n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="6170296fff2a17a1c9ef45405773ce47";
logging-data="6831"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CSKAYfI+t4y4MVBi7dGRL"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:hDp+jHUEZ+emSg5FxdEzYbKSAao=
sha1:WZ0pBe3NktAu326ZJ8ld4etST3s=
 by: Keith Thompson - Tue, 29 Jun 2021 21:39 UTC

Chris Roberts <thecjguy1@gmail.com> writes:
[...]
> I really appreciate everyone's help so much.
> I have this working really well.
> one nagging question:
> I can run my script stand alone fine, but once crontab spits anything out to terminal.
> it won't return to the original prompt.
> ie:
> * * * * * echo "HI" > /dev/tty3
> RETURNS:
> myhost$ HI
>
> (It hangs on a blank line and just sits there, I must hit enter to get out.).
> Any way I can get it to look like so:
> myhost$ HI
> myhost$

crontab has written a message to your terminal, not to your shell. Your
shell has no idea that anything has happened (in particular, it hasn't
executed a command for you), so it has no reason to print a new prompt.

The existing prompt is still active even though your cursor has moved,
so you can just go ahead and type a command to your shell. (By hitting
enter, you're executing an empty command.)

I suppose you could have your cron job print a fake prompt, but it
wouldn't be affected by your shell's $PS1.

Your cron job writes to /dev/tty3. What if you have a different
terminal name next time you login?

You could replace
echo "HI"
by
printf "HI\b\b"
so the message is printed but the cursor goes back to the same place.

You should consider what will happen if the cron job runs while you're
in the middle of typing something. Asynchronous output to an
interactive terminal is always going to be problematic.

Rather than printing to your tty (which could be different every time
you login), consider using something like notify-send. Or if you use
something like GNU screen or tmux, they have message capabilities.
"tmux display-message" works, and can be executed from outside the
session if it can find your current session. For GNU screen, run "info
screen" and search for "Using the message line from your program".

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor