Sponsored Content
Homework and Emergencies Homework & Coursework Questions VM trap may work differently than a pure install trap. Post 302809559 by newuser45 on Monday 20th of May 2013 06:58:39 AM
Old 05-20-2013
VM trap may work differently than a pure install trap.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

That is the last reply I received from my instructor, and I'm looking for some alternatives.

When using the trap command, the echo statement does not return to the console. Instead, there are the spaces, which indicates to me that the echo command is recognized but the termial won't display the characters. This is based on 3 weeks of experience.

I've tried this same script in Knoppix and Ubuntu, both of which are clean installed, and the Toolwire virtual environment that the college provides and cannot get this script to echo as such:

Code:

This is a test program Loop #1 Loop #2 Loop #3 ^C Sorry! I have trapped Ctrl-C Loop #4 Loop #5 Loop #6 Loop #7 ^C Sorry! I have trapped Ctrl-C Loop #8 Loop #9 Loop #10
This is the end of the test program

This is a last ditched effort to solve the problem, the instructor and I have been going at this for a couple of days and it's really time to move on. I still want to solve this so I am reaching out to all of you to see if I can get an understanding of the dynamic happening here. Mostly becuase the book says the script works, it works for the instructor and a classmate, just not me.

I hope I have provided enough information. Let me know if I need to post something else such as a screenshot.

Thank you.
2. Relevant commands, code, scripts, algorithms:

Using the script copied from the text:

Ch. 15, “Script Control,” of Linux® Command Line and Shell Scripting Bible.

System Info:

RHEL = ver 6: 2.6.18-348.4.1.el5
Terminal = Gnome gnome-panel 2.16.1
SHELL = bash
VirtualBox = 4.2.12.r84980


3. The attempts at a solution (include all code and scripts):

Script

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..."

Output

Code:
 
 
Start of the program...
Loop #1
# Should Echo Here {^C}
Loop #2
# Should Echo Here {^C}
Loop #3
Loop #4
Loop #5
Loop #6
...echo
Loop #7
...echo
Loop #8
....echo
Loop #9
End of the program...
[me@localhost ~]$ I have trapped CTRL-C <--the trap echos here.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

University Of Phoenix - Online; Dr. Lori Nicholson; POS 421


Instructor Feedback:

I don't think it has anything to do with you and your code - after I made a few corrections to your script - but I think it may be your system setup.

The trap is captured - that's not the issue. The issue is what happens after the program execution is stopped by the trap. The system will not let it continue one more step and echo out the display to the screen. The trap stops the program but doesn't continue to execute the shell script to the point where we see the text and the echo command is executed.



Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
 

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
All times are GMT -4. The time now is 05:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy