Sponsored Content
Homework and Emergencies Homework & Coursework Questions VM trap may work differently than a pure install trap. Post 302809621 by bakunin on Monday 20th of May 2013 09:21:27 AM
Old 05-20-2013
Quote:
Originally Posted by newuser45
Code:
#! /bin/bash
count=1
trap " echo 'I have trapped CTRL-C'" SIGTERM SIGINT
echo "Start of the program..."
while [ $count -lt 10 ]
        do
        echo "Loop #$count"
        sleep 10
        count=$[ count + 1]
        done
echo "End of the program..."

I pasted the quoted code into a file and ran it and - to my surprise - it worked. I would have expected this:

Code:
        count=$[ count + 1]

to caue problems, it "just doesn't seem right", but then, i use Korn Shell most of the times and avoid bash like the plague. I would have written:

Code:
        (( count += 1 ))

which should do the same and is POSIXly correct (notice the spaces around "((" and "))", they are necessary), but: never argue with success, yours obviously works.

One thing i noticed, though, was: as soon as i pressed "CTRL-C" the trap was executed but the "sleep 10" was interrupted and then skipped. Pressing CTRL-C often enough let me get through with the script in less than half a minute, whereas 10x 10 seconds of sleeping should have taken 1min 40sec (plus some for the rest).

So, probably there is something with your setup. I have no idea what that would be, though. I tried in an XTerm on Fedora without any real changes and it worked as expected.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help with trap

My problem is this: I need to have a catch-all for my processes. An example would be, using a trap, in the parent, to catch any non-0 exit or invalid command (a way to catch core dumps would be cool, too) in not only the parent, but it's children and they're children. Not only that, but I also... (7 Replies)
Discussion started by: marc6057
7 Replies

2. Shell Programming and Scripting

Building a better mouse trap, or How many lines of code does it take to trap a mouse?

Hello all, I'm hoping to get a little insight from some of the wily veterans amongst you. I've written a script to check for new outgoing files to our vendors located on our ssl server. It seems to be working ok, but the final question here, will be one of logic, and/or a better way to... (4 Replies)
Discussion started by: mph
4 Replies

3. UNIX for Advanced & Expert Users

Need help with trap

Hi Our problem is knowing: What is the "best" way of simulating a TRAP for ERR within a function, since we know this will not work directly with ksh93 and aix5. How can we save the error encountered in the function and then deal with it in the calling script? Thanks! (3 Replies)
Discussion started by: theteeth07
3 Replies

4. Shell Programming and Scripting

Trap

Hi All "Identify the behavior of traps, mechanism to implement traps in the snmp framework" What does it mean?? Can anybody explain.. Whats this Trap?? Thanx in Advance. (1 Reply)
Discussion started by: jeenat
1 Replies

5. Shell Programming and Scripting

How to trap

I have a script #!/bin/ksh trap cleanup 20 cleanup() { cat $t.log echo Caught exit 1 } if ;then echo Found >>t.log exit 20 else echo Not found >>t.log exit 20 fi (5 Replies)
Discussion started by: thana
5 Replies

6. Shell Programming and Scripting

Cntl+z Trap is not detecting ??? Help required to add a trap detection ???

Hi folks, I have tried to add some trap detection in the below script....this script is used to monitor database activities...in a rather awkward way :rolleyes:.... The idea behind adding trap is that....this script creates lots of temporary files in the running folder to store the count... (1 Reply)
Discussion started by: frozensmilz
1 Replies

7. Shell Programming and Scripting

trap

Hi At the beginning of my script, i will create a file and at the end of the script i will delete that. But i got to delete the file even if the process is forcefully killed, or server is rebooted... I think i can make use of trap signal, but couldnt figure out how and where to use in my... (4 Replies)
Discussion started by: vasuarjula
4 Replies

8. Shell Programming and Scripting

what does this 'trap' do?

trap "" 1 2 3 Thanks, -dog (1 Reply)
Discussion started by: landog
1 Replies

9. Shell Programming and Scripting

Trap

Hi Ppl, Need help $ cat trap.sh #!/bin/bash trap cleanup 1 2 3 15 cleanup() { echo “I was running \”$BASH_COMMAND\” when you interrupted me.” echo “Quitting.” exit 1 } while : do echo -en “hello. “ sleep 1 (3 Replies)
Discussion started by: heman96
3 Replies

10. Programming

Perl: trap signal 'exit': why I am not able to have it work??

First time trying to work with signals in Perl. Reviewing example I try it, but not able to get it work for 'exit'. I hope, I am correct, assuming, that the ending any code by exit $return_code; the $SIG{EXIT} should be de-referenced and processed?! So, I have such code, that, I assume,... (5 Replies)
Discussion started by: alex_5161
5 Replies
DEBCONF-MERGETEMPLATE(1)					      Debconf						  DEBCONF-MERGETEMPLATE(1)

NAME
debconf-mergetemplate - merge together multiple debconf template files SYNOPSIS
debconf-mergetemplate [options] [templates.ll ...] templates DESCRIPTION
Note: This utility is deprecated. You should switch to using po-debconf's po2debconf program. This program is useful if you have multiple debconf templates files which you want to merge together into one big file. All the specified files will be read in, merged, and output to standard output. This can be especially useful if you are dealing with translated template files. In this case, you might have your main template file, plus several other files provided by the translators. These files will have translated fields in them, and maybe the translators left in the english versions of the fields they translated, for their reference. So, you want to merge together all the translated templates files with your main templates file. Any fields that are unique to the translated files need to be added in to the correct templates, but any fields they have in common should be superseded by the fields in the main file (which might be more up-to-date). This program handles that case properly, just list each of the translated templates files, and then your main templates file last. OPTIONS
--outdated Merge in even outdated translations. The default is to drop them with a warning message. --drop-old-templates If a translation has an entire template that is not in the master file (and thus is probably an old template), drop that entire template. SEE ALSO
debconf-getlang(1) AUTHOR
Joey Hess <joeyh@debian.org> 2012-09-10 DEBCONF-MERGETEMPLATE(1)
All times are GMT -4. The time now is 08:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy