Re: at based alarm.

2018-02-15 Thread David Wright
On Thu 15 Feb 2018 at 08:19:25 (-0800), pe...@easthope.ca wrote:
> * From: Greg Wooledge €wool...@eeg.ccf.org€
> * Date: Tue, 13 Feb 2018 15:01:42 -0500
> > xterm -display :0 -e bash -c '. ~/.bashrc; wake'
> 
> You've lost me.  That command is for a wake function rather than 
> script?  ~/.bashrc is necessary to declare the function before it is 
> invoked?  What is the period preceding ~/.bashrc?
> 
> When that is invoked interactively, the xterm window opens and 
> immediately closes.  No evidence of the wake function executing.

Write …bashrc ; wake ; sleep 5'
and give yourself 5 seconds to read what it says in the xterm.

Cheers,
David.



Re: at based alarm.

2018-02-15 Thread Greg Wooledge
On Thu, Feb 15, 2018 at 08:19:25AM -0800, pe...@easthope.ca wrote:
> * From: Greg Wooledge 
> > xterm -display :0 -e bash -c '. ~/.bashrc; wake'
> 
> You've lost me.  That command is for a wake function rather than 
> script?  ~/.bashrc is necessary to declare the function before it is 
> invoked?  What is the period preceding ~/.bashrc?

You're conflating a few things from the earlier parts of the thread.

The command quoted above is for the use of a wake function that's
defined in ~/.bashrc rather than a script.  In order for the function
to work, its definition has to be read and executed as a command.
Which means the contents of ~/.bashrc have to be read and executed.
That's what dotting in does.

The . command reads the contents of a file and executes it as a
series of shell commands in the CURRENT shell instead of as a
child-process script.  This is called "dotting in".  The syntax was
invented in the 1970s.  Bash offers the "source" command as a
synonym for "." so that people don't keep asking this question
over and over.

The . command was already used by someone else in the thread, so I
didn't change it to source.

If you go with a script named wake (instead of a function named wake)
then you don't have to worry about any of this.

> When that is invoked interactively, the xterm window opens and 
> immediately closes.  No evidence of the wake function executing.

We'd have to see your ~/.bashrc and the actual command you executed.

> For the wake script, both of these work interactively.
> xterm -display :0 -e bash -c '~/wake'
> xterm -display :0 -e ~/wake
> 
> > It would be a lot simpler to put the script in ~/bin/wake though.
> 
> I'm happy to use a script rather than function.  Is the ~/bin location 
> significant?  Would ~ work just as well?

$HOME/bin is the traditional place to put personal shell scripts and other
commands.  Usually one ensures that this directory is part of PATH so
that they can simply be invoked as commands in interactive shells.

Note that the default Debian ~/.profile file in stretch will add
$HOME/bin to your PATH for you, if your login method includes the
reading of this file at all.  Sadly, Display Manager logins do not.



Re: at based alarm.

2018-02-15 Thread peter
*   From: Greg Wooledge wool...@eeg.ccf.org
*   Date: Tue, 13 Feb 2018 15:01:42 -0500
> xterm -display :0 -e bash -c '. ~/.bashrc; wake'

You've lost me.  That command is for a wake function rather than 
script?  ~/.bashrc is necessary to declare the function before it is 
invoked?  What is the period preceding ~/.bashrc?

When that is invoked interactively, the xterm window opens and 
immediately closes.  No evidence of the wake function executing.

For the wake script, both of these work interactively.
xterm -display :0 -e bash -c '~/wake'
xterm -display :0 -e ~/wake

> It would be a lot simpler to put the script in ~/bin/wake though.

I'm happy to use a script rather than function.  Is the ~/bin location 
significant?  Would ~ work just as well?

I still want to have the alarm at a specified time.  Seems at should 
work but it has yet to suceed.

Thanks,  ... Peter E.


-- 

123456789 123456789 123456789 123456789 123456789 123456789 123456789
Tel: +1 360 639 0202  Pender Is.: +1 250 629 3757
http://easthope.ca/Peter.html  Bcc: peter at easthope. ca



Re: at based alarm.

2018-02-13 Thread Greg Wooledge
On Tue, Feb 13, 2018 at 01:58:50PM -0600, David Wright wrote:
> Because .bashrc wasn't called. This might work for a bash function:
> 
> xterm -display :0 -e bash -c  . .bashrc ; wake

You probably meant:

xterm -display :0 -e bash -c '. ~/.bashrc; wake'

It would be a lot simpler to put the script in ~/bin/wake though.



Re: at based alarm.

2018-02-13 Thread David Wright
On Tue 13 Feb 2018 at 08:47:56 (-0800), pe...@easthope.ca wrote:
> Test the function.
> peter@computer:~$ wake
> Yes, it works .
> 
> Test the function with xterm.
> peter@computer:~$ xterm -e wake
> The xterm window opens and immediately closes.  A function 
> is not an acceptable option?
> 
> Try the alarm using the working script.
> peter@computer:~$ echo "xterm -display :0 -e ./wake" | at 6:30
> 
> The xterm window doesn't open but there is no error message 
> to the originating terminal or to syslog.
> 
> I need to understand why "xterm -display :0 -e ./wake" fails for at 
> but works interactively.

Because .bashrc wasn't called. This might work for a bash function:

xterm -display :0 -e bash -c  . .bashrc ; wake

Cheers,
David.



Re: at based alarm.

2018-02-13 Thread Greg Wooledge
On Tue, Feb 13, 2018 at 08:47:56AM -0800, pe...@easthope.ca wrote:
> peter@computer:~$ cat wake
> #!/bin/bash
>   input=""
>   until [[ $input != "" ]] ; do
> echo Beginning until loop.
> /usr/bin/play /home/peter/ring.wav
> read -n 1 -t 4 input
>   done
> 
> Test the script.
> peter@computer:~$ xterm -e ./wake
> Yes, it works for bash.  Appears [[ or read is not available in dash.

The [[ command is a bashism, yes.

The read command is not a bashism, but read -t and read -n *are*.
The only portable option for read is -r.

Since you're relying heavily on the read-with-timeout, just stick
with bash and do not even ATTEMPT it in sh.



Re: at based alarm.

2018-02-13 Thread peter
From: davidson 
Date: Sun, 11 Feb 2018 10:31:25 + (UTC)
> In the "wake" script, you could start xterm with the -e option (and
> put the remainder of your "wake" script in a separate "wake-aux"
> script, I guess):

OK, thanks.  wake is now simplified to this.

peter@computer:~$ cat wake
#!/bin/bash
  input=""
  until [[ $input != "" ]] ; do
echo Beginning until loop.
/usr/bin/play /home/peter/ring.wav
read -n 1 -t 4 input
  done

Test the script.
peter@computer:~$ xterm -e ./wake
Yes, it works for bash.  Appears [[ or read is not available in dash.

Also tried defining a function in .bashrc.
peter@computer:~$ declare -f wake
wake ()
{
  input=""
  until [[ $input != "" ]] ; do
echo Beginning until loop.;
/usr/bin/play /home/peter/ring.wav;
read -n 1 -t 4 input;
  done
}

Test the function.
peter@computer:~$ wake
Yes, it works .

Test the function with xterm.
peter@computer:~$ xterm -e wake
The xterm window opens and immediately closes.  A function 
is not an acceptable option?

Try the alarm using the working script.
peter@computer:~$ echo "xterm -display :0 -e ./wake" | at 6:30

The xterm window doesn't open but there is no error message 
to the originating terminal or to syslog.

I need to understand why "xterm -display :0 -e ./wake" fails for at 
but works interactively.

> I ask about your intent above because this next line...
> 
> until [[ $input != "" ]] ; do
> 
> ...employs the new-fangled Korn shell/Bash conditional test '[[',
> instead of the old-fangled test builtin '['.

bash is now specified.  I'd prefer "test" rather than "[[" but haven't 
found how to make it work.  In common use, "[" and "[[" are delimiters. 
"test" is a better keyword.

Thanks,  ... P.



-- 

123456789 123456789 123456789 123456789 123456789 123456789 123456789
Tel: +1 360 639 0202  Pender Is.: +1 250 629 3757
http://easthope.ca/Peter.html  Bcc: peter at easthope. ca



Re: at based alarm.

2018-02-11 Thread davidson

On Sat, 10 Feb 2018, pe...@easthope.ca wrote:


Given a file named wake containing this script, an alarm can be started with at.
 at -f wake 6:30
How can the xterm be started with std{in,out,err} connected there?

Thanks, ... Peter E.



By the way, it looks to me that the shell interpreter you invoke
here...


#!/bin/sh


...is not bash, but probably dash. Is it your intent to call bash
instead?


xterm
input=""


I ask about your intent above because this next line...


until [[ $input != "" ]] ; do


...employs the new-fangled Korn shell/Bash conditional test '[[',
instead of the old-fangled test builtin '['.

During a brief search of the dash man page, I didn't find any mention
of '[['. Just '['.


 echo Beginning until loop.
 /usr/bin/play /home/peter/ring.wav
 read -n 1 -t 4 input
done






Re: at based alarm.

2018-02-11 Thread davidson

On Sat, 10 Feb 2018, pe...@easthope.ca wrote:


Given a file named wake containing this script, an alarm can be started with at.
 at -f wake 6:30
How can the xterm be started with std{in,out,err} connected there?


In the "wake" script, you could start xterm with the -e option (and
put the remainder of your "wake" script in a separate "wake-aux"
script, I guess):

 $ man 1 xterm
 [...]
 -e program [ arguments ... ]

This option specifies the program (and its command line
arguments) to be run in the xterm window.  It also sets the
window title and icon name to be the basename of the program
being executed if neither -T nor -n are given on the command
line.

NOTE: This must be the last option on the command line.
 [...]



Thanks, ... Peter E.

#!/bin/sh
xterm
input=""
until [[ $input != "" ]] ; do
 echo Beginning until loop.
 /usr/bin/play /home/peter/ring.wav
 read -n 1 -t 4 input
done




at based alarm.

2018-02-10 Thread peter
Given a file named wake containing this script, an alarm can be started with at.
  at -f wake 6:30
How can the xterm be started with std{in,out,err} connected there?

Thanks, ... Peter E.

#!/bin/sh 
xterm
input=""
until [[ $input != "" ]] ; do
  echo Beginning until loop.
  /usr/bin/play /home/peter/ring.wav
  read -n 1 -t 4 input
done

-- 

123456789 123456789 123456789 123456789 123456789 123456789 123456789
Tel: +1 360 639 0202  Pender Is.: +1 250 629 3757
http://easthope.ca/Peter.html  Bcc: peter at easthope. ca