Simple question - Linux

This is a discussion on Simple question - Linux ; Is it possible to redirect the output of a cron job to a shell prompt ? I explain me. If I have a simple script that cron runs every ten minuts to see if a word is present in a ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Simple question

  1. Simple question



    Is it possible to redirect the output of a cron job to a shell prompt ?
    I explain me. If I have a simple script that cron runs every ten minuts
    to see if a word is present in a file. If so it has to direct the output
    I say with echo to a bash prompt.

    Example of script

    #!/bin/sh

    if grep -q e /var/spool/mail/Proprietario
    then echo "ok ci siamo"
    fi

    In this condition, if positive, cron send me an email with the text
    "ok ci siamo". But is it possible to send it to an open terminal on wich I'm
    working ?

  2. Re: Simple question

    On 27 Jul 2008 18:48:01 GMT r wrote:
    |
    |
    | Is it possible to redirect the output of a cron job to a shell prompt ?
    | I explain me. If I have a simple script that cron runs every ten minuts
    | to see if a word is present in a file. If so it has to direct the output
    | I say with echo to a bash prompt.
    |
    | Example of script
    |
    | #!/bin/sh
    |
    | if grep -q e /var/spool/mail/Proprietario
    | then echo "ok ci siamo"
    | fi
    |
    | In this condition, if positive, cron send me an email with the text
    | "ok ci siamo". But is it possible to send it to an open terminal on wich I'm
    | working ?

    It is possible. The next question is how to reliably figure it out. See the
    write command (man page section 1, not the function in section 2).

    --
    |WARNING: Due to extreme spam, googlegroups.com is blocked. Due to ignorance |
    | by the abuse department, bellsouth.net is blocked. If you post to |
    | Usenet from these places, find another Usenet provider ASAP. |
    | Phil Howard KA9WGN (email for humans: first name in lower case at ipal.net) |

  3. Re: Simple question

    On 2008-07-27, phil-news-nospam@ipal.net wrote:
    > On 27 Jul 2008 18:48:01 GMT r wrote:
    >|
    >|
    >| Is it possible to redirect the output of a cron job to a shell prompt ?
    >| I explain me. If I have a simple script that cron runs every ten minuts
    >| to see if a word is present in a file. If so it has to direct the output
    >| I say with echo to a bash prompt.
    >|
    >| Example of script
    >|
    >| #!/bin/sh
    >|
    >| if grep -q e /var/spool/mail/Proprietario
    >| then echo "ok ci siamo"
    >| fi
    >|
    >| In this condition, if positive, cron send me an email with the text
    >| "ok ci siamo". But is it possible to send it to an open terminal on wich I'm
    >| working ?
    >
    > It is possible. The next question is how to reliably figure it out. See the
    > write command (man page section 1, not the function in section 2).


    ok,


  4. Re: Simple question

    On Jul 27, 11:48 pm, r wrote:
    > Is it possible to redirect the output of a cron job to a shell prompt ?
    > I explain me. If I have a simple script that cron runs every ten minuts
    > to see if a word is present in a file. If so it has to direct the output
    > I say with echo to a bash prompt.
    >
    > Example of script
    >
    > #!/bin/sh
    >
    > if grep -q e /var/spool/mail/Proprietario
    > then echo "ok ci siamo"
    > fi
    >
    > In this condition, if positive, cron send me an email with the text
    > "ok ci siamo". But is it possible to send it to an open terminal on wich I'm
    > working ?


    Yes. Just redirect as follows.

    echo "hi" > /dev/pts/1

    /dev/pts/1 assumed to be your open terminal. using tty command you can
    get your terminal name. Hope this helps.
    Thanks and Regards,
    -Saravanan.

  5. Re: Simple question

    Hello,

    r wrote:

    >
    >
    > Is it possible to redirect the output of a cron job to a shell prompt ?
    > I explain me. If I have a simple script that cron runs every ten minuts
    > to see if a word is present in a file. If so it has to direct the output
    > I say with echo to a bash prompt.
    >
    > Example of script
    >
    > #!/bin/sh
    >
    > if grep -q e /var/spool/mail/Proprietario
    > then echo "ok ci siamo"
    > fi
    >
    > In this condition, if positive, cron send me an email with the text
    > "ok ci siamo". But is it possible to send it to an open terminal on wich
    > I'm working ?


    Beware of simple questions.... They are not always easy to answer...

    A cron job of course has no idea what the user is doing on the desktop,
    so to which window should the output be sent???

    The following commands might help:

    mesg y: Allow non-root users, including yourself, to write to your terminal
    write user tty: Write a message to user "user" on specified tty
    who: who is logged on on which terminal


    You can give the script below a try:
    -------------------------------------------------------------------
    #!/bin/sh
    sendoutput()
    {
    #
    #Send a line of output to mail or to mesg-enabled tty
    #
    ttylist=`who -T | grep "^${LOGNAME}.*+.*pts" | awk '{print $3;}'`
    if test -z "$ttylist"
    then
    #No applicable tty, continue to stdout and thus via mail
    echo "$1"
    else
    for i in $ttylist
    do
    echo "$1" | write $LOGNAME /dev/${i}
    done
    fi
    }
    sendoutput "This line has to go out"
    ----------------------------------------------------------------------

    The command "who -T" gives the list of tty's a user is logged on
    and whether this tty is willing to accept messages.

    Remarks:
    -The "write" command itself should be able to figure out
    what the last used "writable" tty is. Failed in my hands.

    -You can try to use "tail" in generating the ttylist to write only to the
    most recently created tty.


    -On my KDE system, there is a process "kded" on /dev/pts/1, which pops up
    when sending a message. May be that's sufficient??? So
    "write user /dev/pts/1" might be sufficient on a KDE system....

    -During testing, I was unable to sent any message to whatever mesg-enabled
    konsole window if the window where I sent the message from is not
    mesg-enabled.
    The null-tty of cron is enabled, so this works.



    Kind Regards,
    H.Janssen












  6. Re: Simple question

    On 2008-07-28, saravanan wrote:
    >
    > Yes. Just redirect as follows.
    >
    > echo "hi" > /dev/pts/1
    >
    > /dev/pts/1 assumed to be your open terminal. using tty command you can
    > get your terminal name. Hope this helps.


    great, I'll try when I'll go back home


  7. Re: Simple question

    On 2008-07-28, H.Janssen wrote:
    >
    > Beware of simple questions.... They are not always easy to answer...
    >
    > A cron job of course has no idea what the user is doing on the desktop,
    > so to which window should the output be sent???
    >
    > The following commands might help:
    >
    > mesg y: Allow non-root users, including yourself, to write to your terminal
    > write user tty: Write a message to user "user" on specified tty
    > who: who is logged on on which terminal
    >
    >
    > You can give the script below a try:
    > -------------------------------------------------------------------
    > #!/bin/sh
    > sendoutput()
    > {
    > #
    > #Send a line of output to mail or to mesg-enabled tty
    > #
    > ttylist=`who -T | grep "^${LOGNAME}.*+.*pts" | awk '{print $3;}'`
    > if test -z "$ttylist"
    > then
    > #No applicable tty, continue to stdout and thus via mail
    > echo "$1"
    > else
    > for i in $ttylist
    > do
    > echo "$1" | write $LOGNAME /dev/${i}
    > done
    > fi
    > }
    > sendoutput "This line has to go out"
    > ----------------------------------------------------------------------
    >
    > The command "who -T" gives the list of tty's a user is logged on
    > and whether this tty is willing to accept messages.
    >
    > Remarks:
    > -The "write" command itself should be able to figure out
    > what the last used "writable" tty is. Failed in my hands.
    >
    > -You can try to use "tail" in generating the ttylist to write only to the
    > most recently created tty.
    >
    >
    > -On my KDE system, there is a process "kded" on /dev/pts/1, which pops up
    > when sending a message. May be that's sufficient??? So
    > "write user /dev/pts/1" might be sufficient on a KDE system....
    >
    > -During testing, I was unable to sent any message to whatever mesg-enabled
    > konsole window if the window where I sent the message from is not
    > mesg-enabled.
    > The null-tty of cron is enabled, so this works.
    >
    >
    >
    > Kind Regards,
    > H.Janssen


    ok, it is a little complex for me who lack programming.
    I'm the only user of the pc so there should not be the need to discover
    what's my tty. Other important point is that I'm using cygwin that is a limited
    linux environment. ( for example, there is no the very useful in this
    case " write " command ).
    When I will arrive home will try if m's advice to redirect to > /dev/console
    runs. And I'll better see your script.

    B regards
    R

  8. Re: Simple question

    indeed

    r wrote:
    > On 2008-07-28, H.Janssen wrote:
    > >
    > > Beware of simple questions.... They are not always easy to answer...
    > >
    > > A cron job of course has no idea what the user is doing on the desktop,
    > > so to which window should the output be sent???
    > >
    > > The following commands might help:
    > >
    > > mesg y: Allow non-root users, including yourself, to write to your terminal
    > > write user tty: Write a message to user "user" on specified tty
    > > who: who is logged on on which terminal
    > >
    > >
    > > You can give the script below a try:
    > > -------------------------------------------------------------------
    > > #!/bin/sh
    > > sendoutput()
    > > {
    > > #
    > > #Send a line of output to mail or to mesg-enabled tty
    > > #
    > > ttylist=`who -T | grep "^${LOGNAME}.*+.*pts" | awk '{print $3;}'`
    > > if test -z "$ttylist"
    > > then
    > > #No applicable tty, continue to stdout and thus via mail
    > > echo "$1"
    > > else
    > > for i in $ttylist
    > > do
    > > echo "$1" | write $LOGNAME /dev/${i}
    > > done
    > > fi
    > > }
    > > sendoutput "This line has to go out"
    > > ----------------------------------------------------------------------
    > >
    > > The command "who -T" gives the list of tty's a user is logged on
    > > and whether this tty is willing to accept messages.
    > >
    > > Remarks:
    > > -The "write" command itself should be able to figure out
    > > what the last used "writable" tty is. Failed in my hands.
    > >
    > > -You can try to use "tail" in generating the ttylist to write only to the
    > > most recently created tty.
    > >
    > >
    > > -On my KDE system, there is a process "kded" on /dev/pts/1, which pops up
    > > when sending a message. May be that's sufficient??? So
    > > "write user /dev/pts/1" might be sufficient on a KDE system....
    > >
    > > -During testing, I was unable to sent any message to whatever mesg-enabled
    > > konsole window if the window where I sent the message from is not
    > > mesg-enabled.
    > > The null-tty of cron is enabled, so this works.
    > >
    > >
    > >
    > > Kind Regards,
    > > H.Janssen

    >
    > ok, it is a little complex for me who lack programming.
    > I'm the only user of the pc so there should not be the need to discover
    > what's my tty. Other important point is that I'm using cygwin that is a limited
    > linux environment. ( for example, there is no the very useful in this
    > case " write " command ).
    > When I will arrive home will try if m's advice to redirect to > /dev/console
    > runs. And I'll better see your script.
    >
    > B regards
    > R


+ Reply to Thread