<?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: CTRL-C trap in shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454405#M12052</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;when putting the script as the login shell in /etc/passwd exit will logout the user.&lt;BR /&gt;If you want to logout at shell level you can kill the session process of the user within you script with:&lt;BR /&gt;&lt;BR /&gt;LOGOUT=`who am i -T|awk '{print "kill -9 " $(NF-1)}'`&lt;BR /&gt;trap "echo logout;$LOGOUT" 2&lt;BR /&gt;&lt;BR /&gt;Regards</description>
    <pubDate>Tue, 17 Oct 2000 10:14:11 GMT</pubDate>
    <dc:creator>Andreas Voss</dc:creator>
    <dc:date>2000-10-17T10:14:11Z</dc:date>
    <item>
      <title>CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454397#M12044</link>
      <description>Gurus out there !!!!!.&lt;BR /&gt;&lt;BR /&gt;Is ther way to trap ctrl-c in a shell script so that nosy, whacky, smart, silly users dont shell out to a place they should not be ?&lt;BR /&gt;&lt;BR /&gt;I mean I dont want them to feel lost in that almost blank green screen!!!!!.&lt;BR /&gt;&lt;BR /&gt;Thanks for any help.</description>
      <pubDate>Tue, 17 Oct 2000 08:40:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454397#M12044</guid>
      <dc:creator>Nalin Uduwawala_1</dc:creator>
      <dc:date>2000-10-17T08:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454398#M12045</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;ctrl-c generates a signal 2 (SIGINT) see man signal.&lt;BR /&gt;So do this:&lt;BR /&gt;&lt;BR /&gt;trap "echo break!; exit" 2&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Tue, 17 Oct 2000 08:42:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454398#M12045</guid>
      <dc:creator>Andreas Voss</dc:creator>
      <dc:date>2000-10-17T08:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454399#M12046</link>
      <description>write :&lt;BR /&gt;&lt;BR /&gt;trap " echo BREAK ; exit " 2&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;federico</description>
      <pubDate>Tue, 17 Oct 2000 08:52:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454399#M12046</guid>
      <dc:creator>federico_3</dc:creator>
      <dc:date>2000-10-17T08:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454400#M12047</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;...or if you prefer for the user not to see anything, but merely want to disable the Cntl_C interrupt, put this in your script:&lt;BR /&gt;&lt;BR /&gt;trap ''INT&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 17 Oct 2000 09:07:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454400#M12047</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2000-10-17T09:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454401#M12048</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Federico and Andreas are right, but with the 'exit' in the trap command the script will still exit.&lt;BR /&gt;&lt;BR /&gt;So, remove the exit and your users will not be able to interrupt the script using Ctrl-C.&lt;BR /&gt;&lt;BR /&gt;Bye,&lt;BR /&gt;Rik.</description>
      <pubDate>Tue, 17 Oct 2000 09:21:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454401#M12048</guid>
      <dc:creator>RikTytgat</dc:creator>
      <dc:date>2000-10-17T09:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454402#M12049</link>
      <description>On other thing is you can view all the signals that you may want to trap , e.g. in your example you wanted to trap ctrl C which is an interrupt if you type kill -l ( thats l for larry not a 1) it will show you all the signals , so you may want to trap more than one .&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Oct 2000 09:25:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454402#M12049</guid>
      <dc:creator>Devbinder Singh Marway</dc:creator>
      <dc:date>2000-10-17T09:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454403#M12050</link>
      <description>Thank you. I will try them out.&lt;BR /&gt;&lt;BR /&gt;In this shell script I want to give users to exit from the terminal session.Out to the password prompt.&lt;BR /&gt;&lt;BR /&gt;Now when I give 'exit' it does not logout.&lt;BR /&gt;&lt;BR /&gt;is there another command for this ? &lt;BR /&gt;&lt;BR /&gt;I type exit and it logs me out .&lt;BR /&gt;&lt;BR /&gt;But in a shell script it does not react the same way.&lt;BR /&gt;&lt;BR /&gt;Thank you again. It is a nice sunny day out here in Richmond. I hope this is same for all of you.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;&lt;BR /&gt;nalin.&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Oct 2000 09:34:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454403#M12050</guid>
      <dc:creator>Nalin Uduwawala_1</dc:creator>
      <dc:date>2000-10-17T09:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454404#M12051</link>
      <description>If you prefer to use Perl, there is a hash called %SIG whose keys are those that the "kill -l" command lists for your system.&lt;BR /&gt;If you assign for any of the signal keys a subroutine reference to the %SIG hash you can write your own signal handlers much better than what trap can offer.&lt;BR /&gt;See the POD "perldoc perlvar" for examples.&lt;BR /&gt;But be cautious, I read in the "Perl Cookbook" that handling system signals through ones own routines can be perilous.</description>
      <pubDate>Tue, 17 Oct 2000 09:37:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454404#M12051</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2000-10-17T09:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454405#M12052</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;when putting the script as the login shell in /etc/passwd exit will logout the user.&lt;BR /&gt;If you want to logout at shell level you can kill the session process of the user within you script with:&lt;BR /&gt;&lt;BR /&gt;LOGOUT=`who am i -T|awk '{print "kill -9 " $(NF-1)}'`&lt;BR /&gt;trap "echo logout;$LOGOUT" 2&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Tue, 17 Oct 2000 10:14:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454405#M12052</guid>
      <dc:creator>Andreas Voss</dc:creator>
      <dc:date>2000-10-17T10:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454406#M12053</link>
      <description>&lt;BR /&gt;Put trap in $HOME/.profile.&lt;BR /&gt;&lt;BR /&gt;There is a patch for ksh and trap, is you use ksh.</description>
      <pubDate>Tue, 17 Oct 2000 10:52:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454406#M12053</guid>
      <dc:creator>Carlos Fernandez Riera</dc:creator>
      <dc:date>2000-10-17T10:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454407#M12054</link>
      <description>Anreas and others ,&lt;BR /&gt;&lt;BR /&gt;Thanks for your input. I have the login sscipt in each person's .profile. Do I use vi to edit the etc/password file ? What will then happen to the stuff in the  .profile for eah user ? do I delete it ?</description>
      <pubDate>Tue, 17 Oct 2000 11:30:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454407#M12054</guid>
      <dc:creator>Nalin Uduwawala_1</dc:creator>
      <dc:date>2000-10-17T11:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454408#M12055</link>
      <description>Hi,&lt;BR /&gt;Include the following in the users .profile and also the /etc/profile file:&lt;BR /&gt;[(trap "" 1 2 3 9 15) and stty intr "^C" or stty intr "".]</description>
      <pubDate>Tue, 17 Oct 2000 11:31:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454408#M12055</guid>
      <dc:creator>CHRIS_ANORUO</dc:creator>
      <dc:date>2000-10-17T11:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454409#M12056</link>
      <description>As Chris says, remember to trap ALL the signals, since CTRL-PIPE and other combinations might cause the same as CTRL-C, and if you trap only CTRL-C these holes are still open.</description>
      <pubDate>Sat, 24 Feb 2001 19:04:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454409#M12056</guid>
      <dc:creator>Emiliano Diez</dc:creator>
      <dc:date>2001-02-24T19:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: CTRL-C trap in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454410#M12057</link>
      <description>It's important to understand what the trap signal is really affecting.  In the standard /etc/profile, you will see at the beginning:&lt;BR /&gt;&lt;BR /&gt;trap "" 1 2 3&lt;BR /&gt;&lt;BR /&gt;and at the end&lt;BR /&gt;&lt;BR /&gt;trap 1 2 3&lt;BR /&gt;&lt;BR /&gt;This prevents anyone from exiting from the login shell during /etc/profile, a good thing as you can use /etc/profile to deny access to a particular user by exiting to return to the login/password prompt. This trap affects the login shell only.&lt;BR /&gt;&lt;BR /&gt;Just a note about turning traps on/off: In the /etc/profile example, trap "" 1 2 3 says: "Do nothing for signals 1 2 3 (also known as SIGHUP SIGINT SIGQUIT) if they occur during this script's execution."&lt;BR /&gt;&lt;BR /&gt;Now, if you leave off the last line (trap 1 2 3) which reenables the traps to normal behavior, things will seem OK unless your session is aborted with a hangup (disconnect). Now your shell can't respond as it was told to ignore SIGHUP so it runs in a loop forever as there is controlling tty.&lt;BR /&gt;&lt;BR /&gt;In your .profile, you can also disable traps the same way.  And if you take an early exit from .profile, you will be returned to the login/password prompt.&lt;BR /&gt;&lt;BR /&gt;However, if you run another script from .profile, you are no longer in your logoin shell, but a subshell so when you exit, you return back to your parent shell.&lt;BR /&gt;&lt;BR /&gt;A solution is to run your script in the parent shell. This is done with 'sourcing' your script using the . (dot) command. Instead of running your script in .profile with just the script's filename, put a dot space in front of it as in:&lt;BR /&gt;&lt;BR /&gt;. /usr/contrib/bin/myscript&lt;BR /&gt;&lt;BR /&gt;This tells the shell to read each line as if it was typed in at the keyboard. Now an exit in myscript will tell the login shell to exit.&lt;BR /&gt;&lt;BR /&gt;All of this assumes standard /usr/bin/sh (the POSIX shell). If your users insist on using strange shells (like csh) then you'll have to become familiar with their login process(like /etc/csh.login) and how to handle traps in those shells.</description>
      <pubDate>Sat, 24 Feb 2001 23:49:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ctrl-c-trap-in-shell-script/m-p/2454410#M12057</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2001-02-24T23:49:12Z</dc:date>
    </item>
  </channel>
</rss>

