I'm trying to increase usabilty for my scripted project-, for that i wanted to apply an error message poping up upon every and any error (other than proper exit) indicating the enduser a uniform, and hopefully readable error messsage.
To achieve this, i wrote a msg_error function, and prepared some trap handling...
My issue isnt this... well at least not really..
My issue is the follow up, when callling a script with the same name (but which is intended to be executed, while this generated script is ment to be sourced).
Somehow the \$\' doesnt return the values expected, not even with grepping all files.
So the search for one of the errrors ($'\212.... not found) became more complicated than expected...
I dont understand where the invalid signal spec comes from?
Specialy since calling the /etc/tuirc script by itself, it closes without error, but sourcing from other files, it raises one, in way i cant follow the reason.
Any ideas or advices please?
Thank you in advance.
I'm confused. The title of this thread is "[BASH] Errormessages and Traps with a 'here-doc'", but I don't see any here-documents anywhere in the code you've shown us?
In the command:
the standards say that setting a trap for SIGKILL produces undefined results. So you might want to try this without the KILL parameter. (There is no way for any process to catch a SIGKILL signal.)
Also, in the commands:
one might expect that the variable used by these two functions would be the same.
This User Gave Thanks to Don Cragun For This Post:
In fact you quoted parts of the 'here-doc', but you're right it isnt obvious.
Thought it was, due to the escapes.
Also, seems i was editing my post while you wrote the answer, i've already removed the 'kill' signall, with no change.
Sorry about that.
The traps_{save,restore} arent (really) used yet (outside of that script).
As of now (past, until now), the generated ./tuirc did only contain TUI_DIR_{variables}, and the injection_protection.
Which was sourced by the already existing and hardcoded ./bin/tuirc. (which is either sourced or executed - to config, etc).
End goal is to replace the current hardcoded ./bin/tuirc with the generated ./tuirc which - as soon it works - will become the ./bin/tuirc.
But i guess this is only relevant to me.
Anyway, here's the full script: ./scripts/gen-tuirc.sh
NOTE: the commented out cat tuirc.tpl results in an endless loop, as the *tpl was not adjusted to the recent changes (it still sources 'itself' as its origin is/was bin/tuirc).
Also, all the functions/variables of the *tpl file are already present in the executed (not visible here) bin/tuirc.
Simple said, the only NEW parts are msg_error and everything below until EOS.
Changing back there helps, to get rid of the 'invalid signal' messages.
However, these remains:
I do know i've used 'somewhere' 'something like' (pseudo code): $'var'
But me cant find that anymore...
By now i still have no idea why the invalid signals occour, or why i cant find the $' in any scripts...
Any ideas or advice from here?
Thank you in advance.
The diagnostic:
doesn't mean that bash was trying to execute something specified using $'...', it just means that it was asked to execute a command whose name was specified as those three octal valued bytes (which do not form valid characters in the current locale), and there was no command found in $PATH matching that name. Try:
instead of:
and if that doesn't work either, try looking for a lowercase letter b followed by a backspace. (If the last one works and you don't see why I made that wild guess, ask me after it works.)
Note that if you have something like:
in your code somewhere such that it is being treated as a command name, it might be even harder to find. (Like maybe the double backslashes in the printf statement in msg_error() are causing the output from the getconf command substitutions to be executed???)
As always, bash -xv script [arg...] is your friend when trying to find out where something is going wrong.
For the record, you still have:
in your script. And in the two lines in your code:
I would have guessed that the tc marked in red above should be tl.
This User Gave Thanks to Don Cragun For This Post:
Was great, figured during copy paste of a trap example, i copied − and didnt change to - .
So we're back to the wrong signal.
I tried to provide the 2 most essential parts, around the loading of the generated rc file (see above), and the (still the same) errors where the actual output happens.
VISUAL DIVIDER
In the end, the interesting part is - it prints the output as expected, just with a leading error output...
Something i just realized...
As the userinput was 'n', which was taken as a trap signal, i'm more confused on this subject than ever.
I removed 'INT' now, since i belive ctrl+c should not raise an error message.
Just to verify if 'everyting else' is working properly, i've redirected stderr to null "temporary".
Q (follow up): I'm afraid it'll always will be line 130, unless i define the trap somewhere else again?
As in this example: <cmd> || msg_error [args...]
---------- Post updated at 15:25 ---------- Previous update was at 13:31 ----------
I dont like it, but very often echo seems the solution...
/solved
Hi,
I tried to run snmptrapd from my customized service in centos 5.7 machine... the command used to start snmptrapd is ....
/opt/snmpdemo/bin/snmptrapd -Le -c /opt/snmpdemo/etc/snmp/snmptrapd.conf -n -C -t -m ""
And tried to trigger a trap... Trap got triggered but snmptrapd didn't... (0 Replies)
Hi all Solaris Experts,
What are the traps and pitfalls in using Solaris zones?
Specifically, what tools, utilities, system calls don't work or work differently in a non-global zone?
I'm new to zones and I've already encountered one difference which is very significant to me:
orphan... (5 Replies)
Hi,
We are using Zyrion Traverse to monitor all the servers. I like to set the traps on all of the Linux servers to send the traps to that servers.
So for on the /etc/snmp/snmp.conf file, this is what I have...
### SNMP Traps ###
trap2sink x.x.x.x # Traverse server
My... (4 Replies)
Hello everyone!
I have a text file with the next content:
2010-04-15 15:21:15 Minor 15605325 1531 Alarm name = IAD Equipment In Service location=iad01.tecnac.camino.illapel, Module=26
and I want send traps with the informationn of this file.
How I can do this?
Many... (3 Replies)
Hi all,
lately i managed to install SNMP agent on Solaris 9 & 10. The second objective is now to configure traps. However (since i'm totally new to the SUN world) i don't know a way of how to start. Can somebody help me with details? What is the first thing that you need to do to start trapping?... (3 Replies)
Hello there....unix users :)
I hope you can help me with this:
I need open a doc file or xls files and work this files whit a bash script.
For example: Open a doc file and copy information from a txt file in this doc file or xls file.
Is it possible?
Sorry for my english...I'm chilean... (3 Replies)
Good morning to you all
I´m kinda of a noob to scripting, and my knowledge is still very basic: anyway, I´ve developed a small .sh script with the following purpose:
- it will check a result file, checking if it has any values, or if it´s empty
- if it´s empty it will send an email
What... (0 Replies)
Hi all,
I have a Sun Solaris 9 box which acts as a firewall. Sometimes if multiple actions which cause snmp traps occur very close together, a single snmp trap that is sent containing the text for multiple alarms. I would like to prevent that and have a trap sent for each action which would... (0 Replies)
Well, I don't know where exactly to ask this doubt so I'm asking in the newbie section. I was reading about traps and interrupts when I thought of traps as something that cease the control of the OS from the user and interrupts that cease the control yet provide support for multitasking. Am I right... (3 Replies)
Hello
I am trying to check that SNMP traps could be sent from one server to other .
I am running this command from receiving server to see it can receive it
/usr/sbin/snoop udp port 162
and on the sending end I am running this commad
cst051 UDP D=162 S=1480 LEN=120
but i am... (1 Reply)