<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: C-shell and terminal attachment check in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919881#M104281</link>
    <description>This is a common problem for all user logins. A properly written /etc/csh.login and .cshrc file will test whether the session is interactive or run in batch mode such as in cron. Note that tset is not the only command that must be excepted. All of these require a 'real' terminal and must be skipped in batch mode:&lt;BR /&gt; &lt;BR /&gt;tput ttytype tabs stty&lt;BR /&gt; &lt;BR /&gt;And while you're at it, I would also skip login messages such as /etc/copyright, /etc/motd, and checks like news and mail. This reduces the junk in email from cron or logs.</description>
    <pubDate>Mon, 22 Aug 2005 20:24:34 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2005-08-22T20:24:34Z</dc:date>
    <item>
      <title>C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919874#M104274</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a problem with C-shell...&lt;BR /&gt;&lt;BR /&gt;The problem is this single line in the .login file of the c-shell user ”sap1”:&lt;BR /&gt; eval `tset -s -Q -m ':?hp' `&lt;BR /&gt;&lt;BR /&gt;which causes commands like the following:&lt;BR /&gt;su – sap1 -c "whatever start"&lt;BR /&gt;to prompt for a terminal&lt;BR /&gt;&lt;BR /&gt;.... unpractical for crontab execution!&lt;BR /&gt;&lt;BR /&gt;I am aware that expect or line deletion could solve the problem. But I would prefer something in the  .login file of sap1 which would check whether a terminal was connected, i.e. c-shell functionality corresponding to "if [[ -t 0 ]]" of the Bourne-shell.&lt;BR /&gt;&lt;BR /&gt;However, I cannot find anything like that. Can anybody help?&lt;BR /&gt;  &lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Mon, 22 Aug 2005 06:01:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919874#M104274</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2005-08-22T06:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919875#M104275</link>
      <description>You can use test -t 0 as if [[ -t 0 ]] in cshell rgt?&lt;BR /&gt;&lt;BR /&gt;% test -t 0 &amp;amp;&amp;amp; echo ok&lt;BR /&gt;&lt;BR /&gt;Or else you can check with who command output to check terminal connectivity.&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Mon, 22 Aug 2005 06:24:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919875#M104275</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-22T06:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919876#M104276</link>
      <description>Sorry. that should be as,&lt;BR /&gt;&lt;BR /&gt;% test -t 0 || echo ok&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Mon, 22 Aug 2005 06:26:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919876#M104276</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-22T06:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919877#M104277</link>
      <description>Another way ...&lt;BR /&gt;&lt;BR /&gt;if ( $?prompt ) then&lt;BR /&gt;...&lt;BR /&gt;endif</description>
      <pubDate>Mon, 22 Aug 2005 06:40:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919877#M104277</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2005-08-22T06:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919878#M104278</link>
      <description>Thank you guys,&lt;BR /&gt;&lt;BR /&gt;Muthukumar,&lt;BR /&gt;I have tried with this constructuion in sap1's .login:&lt;BR /&gt;test -t 0 &amp;amp;&amp;amp; eval `tset -s -Q -m ':?hp' `&lt;BR /&gt;&lt;BR /&gt;which apparently works when activated from cron in a Bourne_shell script containing a line like this:&lt;BR /&gt;su - sap1 -c "system start"&lt;BR /&gt;&lt;BR /&gt;and the very same Bourne-shell script prompts for a terminal in interactive mode. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Ermin,&lt;BR /&gt;can you please elaborate a little on your response? Does it mean that if the prompt has not already been set, then you enter the if-sentence?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Points will be assigned later!&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Mon, 22 Aug 2005 08:13:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919878#M104278</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2005-08-22T08:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919879#M104279</link>
      <description>If it is about cron jobs, I would prefer doing following. Will work accross all shells.&lt;BR /&gt;&lt;BR /&gt;if tty -s&lt;BR /&gt;then&lt;BR /&gt;INTERACTIVE=/sbin/true&lt;BR /&gt;else&lt;BR /&gt;INTERACTIVE=/sbin/false&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Mon, 22 Aug 2005 08:34:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919879#M104279</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2005-08-22T08:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919880#M104280</link>
      <description>csh variable 'prompt' is defined for interactive shells only.&lt;BR /&gt;&lt;BR /&gt;if ( $?prompt ) then&lt;BR /&gt;eval `tset -s -Q -m ':?hp'`&lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;Therefore tset will be run for interactive shells only. Shells run from crontab are not interactive so section enclosed by if statement will be ignored.&lt;BR /&gt;&lt;BR /&gt;However, in your case when shell script is run from command line tset will run because shell is interactive.&lt;BR /&gt;&lt;BR /&gt;If you don't want to get asked for terminal type try using&lt;BR /&gt;&lt;BR /&gt;if ( $?prompt ) then&lt;BR /&gt;eval `tset -s -Q`&lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;If you include ':?hp' part, then tset always asks for terminal type and defaults to terminal type 'hp'.&lt;BR /&gt;&lt;BR /&gt;Alternative to tset is ttytype command which is used to identify terminal type.&lt;BR /&gt;&lt;BR /&gt;eval `ttytype -s`&lt;BR /&gt;&lt;BR /&gt;will automatically detect and set the terminal type.</description>
      <pubDate>Mon, 22 Aug 2005 19:36:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919880#M104280</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2005-08-22T19:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919881#M104281</link>
      <description>This is a common problem for all user logins. A properly written /etc/csh.login and .cshrc file will test whether the session is interactive or run in batch mode such as in cron. Note that tset is not the only command that must be excepted. All of these require a 'real' terminal and must be skipped in batch mode:&lt;BR /&gt; &lt;BR /&gt;tput ttytype tabs stty&lt;BR /&gt; &lt;BR /&gt;And while you're at it, I would also skip login messages such as /etc/copyright, /etc/motd, and checks like news and mail. This reduces the junk in email from cron or logs.</description>
      <pubDate>Mon, 22 Aug 2005 20:24:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919881#M104281</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-08-22T20:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919882#M104282</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;I have tried a variety of combinations in .login:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;A:&lt;BR /&gt;test -t 0 &amp;amp;&amp;amp; eval `tset -s -Q -m ':?hp'&lt;BR /&gt;&lt;BR /&gt;Prompts for terminal in interactive mode.&lt;BR /&gt;Does not hang when executed from crontab.&lt;BR /&gt;Does not produce error messages when executed from crontab.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;B:&lt;BR /&gt;if ( $?prompt ) then&lt;BR /&gt;        eval `tset -s -Q -m ':?hp'`&lt;BR /&gt;        stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z" hupcl ixon ixoff tostop tabs&lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;Prompts for terminal in interactive mode.&lt;BR /&gt;Does not hang when executed from crontab although it enters the if-sentence (?!), which produces the normal error messages from tset and stty. (not quite what I had expected, but perhaps I have not used it correctly).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;C:&lt;BR /&gt;setenv INTERACTIVE no&lt;BR /&gt;test -t 0 &amp;amp;&amp;amp; setenv INTERACTIVE yes&lt;BR /&gt;if ( "${INTERACTIVE}" == "yes" ) then&lt;BR /&gt;        eval `tset -s -Q -m ':?hp'`&lt;BR /&gt;        stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z" hupcl ixon ixoff tostop tabs&lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;Prompts for terminal in interactive mode.&lt;BR /&gt;Does not hang when executed from crontab.&lt;BR /&gt;Does not produce error messages when executed from cron.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you for your responses; as you can see, they were all useful.&lt;BR /&gt;- and thanks for mentioning the "news" command, whose existance I had till now completely ignored! &lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 23 Aug 2005 06:50:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919882#M104282</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2005-08-23T06:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: C-shell and terminal attachment check</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919883#M104283</link>
      <description>quite difficult to make points stick, but now they are there. Case closed.&lt;BR /&gt;</description>
      <pubDate>Tue, 23 Aug 2005 06:53:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-shell-and-terminal-attachment-check/m-p/4919883#M104283</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2005-08-23T06:53:30Z</dc:date>
    </item>
  </channel>
</rss>

