Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Script to compare time stamp on two files and if different report to terminals.

6 views
Skip to first unread message

Helmut Waitzmann

unread,
Mar 14, 2018, 9:18:19 AM3/14/18
to
me at <my.ad...@is.invalid>:

> The script newmail-maildir written by someone a long time ago
> no longer works.
> I have procmail touch $HOME/.mail-semaphore with every mail that arrives.
> Then have this script run every few minutes by crontab and
> print an alert to the screen. It has bits and pieces cobbled
> together from other scripts I have that I think do similar
> things.
> It does not work because I don't know what I am doing.

When “cron” runs the script: Does it send any error messages to
<your_user...@sh.sonic.net>?

> Linux sh.sonic.net 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25
> 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

[…]

> #!/bin/sh
> #!/bin/bash
> # newmail-semaphore
> # 20180305
>
> ### check if .mail-semaphore has a later timestamp than .mail-semaphore-flag
>
> # if [[ "$HOME/.mail-semaphore-flag" -lt "$HOME/.mail-semaphore" ]]
> if [[ "$HOME/.mail-semaphore-flag" -nt "$HOME/.mail-semaphore" ]]
>
> then
>
> ### printed $HOME/.mail-semaphore to the screen.
>
> cat $HOME/.mail-semaphore | /usr/local/bin/tellme.pl

I don't know anything about “/usr/local/bin/tellme.pl”. If you
append the command

“date | /usr/local/bin/tellme.pl

to your script, does it print the date to your screen every few
minutes?

Bit Twister

unread,
Mar 14, 2018, 9:30:43 AM3/14/18
to
On Wed, 14 Mar 2018 11:39:09 +0000 (UTC), me at wrote:
>
> Good Morning,

Same to you. I suggest you need to set your editor to line wrap at 72
characters. Subject matter experts may not bother to reply if they
have to re-wrap your post to Usenet guidelines.

Might not hurt for you to create a $HOME/.signature file and tell tin
to append it to your posts. In it you would put a brief description of
you distribution, release level, Desktop Environment. That way subject
matter experts may provide better answers.

I suggest a script to automagically create it upon login.

You might also want to duplicate the Subject text in the body of your
reply. One: subject matter experts are busy people and may not bother
reading Subject line but just the post. If they do reply it may be to
the Subject its self and have to copy it into their reply. So hang on
a minute while I straighten up your post. . . . . . . . . . . . . .

> Script to compare time stamp on two files and if different report to
> terminals.

Reporting to terminal would depend on Distribution and what packages
are used and what Desktop Environment you are using.

To answer your question, you can use the "stat" command to get just
about anything you want to know about a file.

As for reporting to a terminal, I can suggest xmessage,
(k,g,c,x)dialog, zenity, .....

Again, default install of those tools depend on Distribution and
Desktop Environment.

> My current ISP moved to a new server and changed email to imap.
> The script newmail-maildir written by someone a long time ago no
> longer works.

Then I would recommend a re-write to something you can maintain. I
have basically the same requirement you have. For example, here you
can see I have created
$ grep --count thunderbird /etc/passwd
6
user accounts to pull down email from different email servers.
What I did was use fetchmail to haul down any email in the up-line
server inbox via a user cron job running hourly.

The mail winds up in /var/mail/user_id_here.

I then have a root hourly cron job to check all files in /var/mail and
if any file byte size is greater than 980, I pop up a xmessage on
whatever window I happen to be running. I can either paste the message
into a terminal, which will automagically log me into the user
account(s) or click a desktop shortcut to log into the desired user account
which launches thunderbird. It in turn pulls down the message(s) and I
can do whatever I like about the new message.

Since I do not use procmail, I can not help with your script. You
should be able to use this snippet of code pulled out of the while loop"

_count=$(stat -c %s /var/spool/mail/$_user)
if [ $_count -gt $_mail_size ] ; then
_has_mail=${_has_mail}${_xcolon}$_user
_xcolon="; x"
if [ "$_user" = "gmail" ] ; then
/local/bin/play_alarm
fi
fi

to give you an idea on getting/using date instead of size. I left in
the other if statement to show I even play an alarm if any mail shows
up in the "gmail" user inbox. That is email from my bank which
notifies me when there is any activity on my bank account.

In no particular order, you might find a few of these useful. Ignore
the '!' comment/keyword string used to find these when using the url.

$ urls doc bash
http://tldp.org/LDP/Bash-Beginners-Guide/html/ ! document
https://www.sourceware.org/autobook/autobook/autobook_119.html#Test ! bash documentation
http://cli.learncodethehardway.org/bash_cheat_sheet.pdf ! command document cmd line
http://www.freeos.com/guides/lsst/ ! bash Linux Shell Scripting Tutorial documentation
http://bahmanm.com/blogs/command-line-options-how-to-parse-in-bash-using-getopt ! document
http://spin.atomicobject.com/2011/03/30/parsing-arguments-in-bash-with-getopts/ ! document command (best)
http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html ! document
http://cfajohnson.com/shell/?2004-05-22_shell_websites ! bash doc reference
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html ! basic shell bash doc
http://cfaj.freeshell.org/shell ! bash script tips usage doc
http://tldp.org/LDP/abs/html/index.html ! bash advanced documentation
http://mywiki.wooledge.org/BashFAQ/050 ! bash variable expansion document
http://mywiki.wooledge.org/BashGuide ! document
http://mywiki.wooledge.org/FullBashGuide ! document



0 new messages