[opensuse] BASH - Why does trap output 45 blank lines to the terminal?
Listmates,
I set up a simple trap to gzip any open files on scripts interrupt or exit:
cleanup () {
echo -e "\n\tExecuting cleanup from trap\n"
[[ -e $NEWFILE ]] && gzip --force --quiet $NEWFILE
[[ -e $XMLFILE ]] && gzip --force --quiet $XMLFILE
}
trap cleanup SIGINT SIGTERM EXIT
rest of script....
trap works correctly, but when it is called, it seems to be inserting 45
blank-lines after the original command line causing the terminal to scroll-up.
Looks odd:
08:33 alchemy:~/linux/scripts/parse> sh xmlparse test.xml.gz
On Wednesday March 25 2009, David C. Rankin wrote:
Listmates,
I set up a simple trap to gzip any open files on scripts interrupt or exit:
cleanup () { echo -e "\n\tExecuting cleanup from trap\n" [[ -e $NEWFILE ]] && gzip --force --quiet $NEWFILE [[ -e $XMLFILE ]] && gzip --force --quiet $XMLFILE
}
trap cleanup SIGINT SIGTERM EXIT
rest of script....
trap works correctly, but when it is called, it seems to be inserting 45 blank-lines after the original command line causing the terminal to scroll-up. Looks odd:
It's certainly not trap or you echo command that's doing that. I'd look to the behavior of whatever command is being interrupted. Also, you might want to capture the output and see if it's really just 45 newlines or possibly something else.
...
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Randall R Schulz wrote:
On Wednesday March 25 2009, David C. Rankin wrote:
Listmates,
I set up a simple trap to gzip any open files on scripts interrupt or exit:
cleanup () { echo -e "\n\tExecuting cleanup from trap\n" [[ -e $NEWFILE ]] && gzip --force --quiet $NEWFILE [[ -e $XMLFILE ]] && gzip --force --quiet $XMLFILE
}
trap cleanup SIGINT SIGTERM EXIT
rest of script....
trap works correctly, but when it is called, it seems to be inserting 45 blank-lines after the original command line causing the terminal to scroll-up. Looks odd:
It's certainly not trap or you echo command that's doing that. I'd look to the behavior of whatever command is being interrupted.
Also, you might want to capture the output and see if it's really just 45 newlines or possibly something else.
...
-- David C. Rankin
Randall Schulz
Randall, You are on to something. While I counted 45 lines in konsole, evidently "They're not lines." Here is what I see on konsole: 14:23 alchemy:~/linux/scripts/parse> sh xmlparse test.xml.gz | nl 1 Executing cleanup from trap 14:26 alchemy:~/linux/scripts/parse> So we have a 45 line representation of something on konsole. Taking Aaron's advise I 'set -x' at the top of the script and it has generated a great many hieroglyphs on konsole. Looking at the trap stuff, I see: 14:32 alchemy:~/linux/scripts/parse> sh xmlparse test.xml.gz + trap cleanup SIGINT SIGTERM EXIT <big snip> + exit 0 + cleanup + echo -e '\n\tExecuting cleanup from trap\n' Executing cleanup from trap + [[ -e out-1238009586.xml ]] + gzip --force --quiet out-1238009586.xml + [[ -e test.xml ]] + gzip --force --quiet test.xml Here trap was called on exit and it doesn't give me any indication of where all the space is coming from. I did try removing the 'echo' statement from cleanup(), but you were right, it made no difference. What is really strange, is I modified the trap to remove the 'EXIT' signal and just added cleanup at the end to cover the normal exit. Still it makes no difference. As long as trap is in the script, I get the big blank... Any other thoughts?? -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wednesday March 25 2009, David C. Rankin wrote:
Randall R Schulz wrote:
...
Also, you might want to capture the output and see if it's really just 45 newlines or possibly something else.
...
Randall,
You are on to something. While I counted 45 lines in konsole, evidently "They're not lines." Here is what I see on konsole:
14:23 alchemy:~/linux/scripts/parse> sh xmlparse test.xml.gz | nl ... 1 Executing cleanup from trap
That suggests the output is going to the standard error, which by default is not redirected by a pipe. If you want it to be included, use this: % sh xmlparse test.xml.gz 2>&1 | nl That will merge the standard error of the command with its standard output and the combined stream will be redirected into the pipe.
...
What is really strange, is I modified the trap to remove the 'EXIT' signal and just added cleanup at the end to cover the normal exit. Still it makes no difference. As long as trap is in the script, I get the big blank...
Any other thoughts??
If it's not too long, why don't you post the whole script (and attach it, don't sent it in the message text).
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wednesday 25 March 2009 20:40:49 David C. Rankin wrote:
You are on to something. While I counted 45 lines in konsole, evidently "They're not lines." Here is what I see on konsole:
14:23 alchemy:~/linux/scripts/parse> sh xmlparse test.xml.gz | nl <snip> Any other thoughts??
Could you post the xmlparse script? ANders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Anders Johansson wrote:
On Wednesday 25 March 2009 20:40:49 David C. Rankin wrote:
You are on to something. While I counted 45 lines in konsole, evidently "They're not lines." Here is what I see on konsole:
14:23 alchemy:~/linux/scripts/parse> sh xmlparse test.xml.gz | nl <snip> Any other thoughts??
Could you post the xmlparse script?
ANders
Anders, I would be glad to now. 20 minutes ago I would have been a wee-bit embarrassed. I found the culprit. (ducking...) there was a stray echo. Since the test.xml.gz file only contained 5 xml blocks from the repository metadata file deltainfo.xml.gz and the xml schema for the files has, at a maximum, 9 entries that make up each xml block, the stray echo was just in the exact perfect place to produce 45 blank likes (5 blocks x 9 entries per block = 45 blank lines generated. However, it is fixed now and I can now build my custom deltainfo.xml.gz from the master file at openSuSE Updates by parsing the master file for filenames that exist on my local update repository and when a matching rpm is found the xml block for that rpm is written to my deltainfo.xml.gz. Beats the hell out of cutting and pasting from a 370,000 line xml file. Sorry about the fat-finger error on my part here, but I really do appreciate the help. Also, if anyone else is running their own local update server for local machines, this script is worth it weight in gold. In case anybody else can make use of it, here it is: #!/bin/bash --norc ## ## Title: ## Name: ## Usage: ## Version: 0.0.1 ## Date: 03/23/2009, 04:53:03 PM ## Author: David C. Rankin, J.D.,P.E ## Summary: ## ## Run as: ## Requires: http://ftp5.gwdg.de/pub/opensuse/update/11.0/repodata/deltainfo.xml.gz ## ## #. /home/david/linux/scripts/include/general.inc #. /home/david/linux/scripts/include/colors.inc ## # usage () { echo -e "\n\tUsage: ${0##*/} filename.xml.gz [newfile.xml]\n" echo -e "\tThis script parses the openSuSE deltainfo.xml.gz XML file and" echo -e "\ttests if the filenames contained are present in the local update" echo -e "\trepository. If the file is present, then the XML block for the" echo -e "\tfilename is written to a newfile to create the local deltainfo.xml.gz" echo -e "\tfile.\n" } cleanup () { [[ -e $NEWFILE ]] && gzip --force --quiet $NEWFILE [[ -e $XMLFILE ]] && gzip --force --quiet $XMLFILE } trap cleanup SIGINT SIGTERM EXIT writexml () { for (( i=$PATCHINFO; i < ${#ENTRY[@]}; i++ )); do if [[ -n $1 ]]; then OUTFILE=$1 case $i in 3 ) echo "<filename>${RPMDIR}/${ENTRY[$i]}</filename>" >> $OUTFILE;; 5 ) echo "<size>${ENTRY[$i]}</size>" >> $OUTFILE;; * ) echo "${ENTRY[$i]}" >> $OUTFILE;; esac else case $i in 3 ) echo "<filename>${RPMDIR}/${ENTRY[$i]}</filename>";; 5 ) echo "<size>${ENTRY[$i]}</size>";; * ) echo "${ENTRY[$i]}";; esac fi done } [[ ! -r $1 ]] && { echo -e "\n Unable to read file: '${1:-"[NoneGiven]"}', \ exiting...\n"; usage; exit 1; } [[ ! $1 =~ '.gz' ]] && { echo -e "\n\tInvalid File Format. The file supplied: $1 \ is not a valid GNU zip file, exiting...\n"; exit 1; } let CLINE=0 DLINE=0 BLOCKNO=0 HEADERLINES=2 declare -a ENTRY LOCDELTA XMLFILEGZ=$1 XMLFILE=${XMLFILEGZ%.gz} NEWFILE=${2:-"out-$(date '+%s').xml"} REMHOST=nirvana REMDIR=/home/backup/rpms/openSUSE_11.0/delta FOOTER="</deltainfo>\n" PATCHINFO=1 BLOCKDONE=no DEBUG=no ERRLOG=${3:-${XMLFILE%%.*}.err} [[ ! -r /tmp/deltafiles ]] && ssh $REMHOST "ls -1 $REMDIR" > /tmp/deltafiles while IFS=$'\n' read line; do LOCDELTA[$DLINE]=$line # echo "[$DLINE] ${LOCDELTA[$DLINE]}" ((DLINE+=1)) done < /tmp/deltafiles gunzip $XMLFILEGZ --force --quiet while IFS=$'\n' read line; do ((CLINE+=1)) if [[ $CLINE -le "$HEADERLINES" ]]; then echo $line >> $NEWFILE else case ${line:1:2} in !- ) ENTRY[0]=$line PATCHINFO=0;; ne ) ENTRY[1]=$line;; de ) ENTRY[2]=$line;; fi ) tmpline=${line%<*} tmpline=${tmpline#*>} RPMDIR=${tmpline%/*} ENTRY[3]=${tmpline##*/};; se ) ENTRY[4]=$line;; si ) tmpline=${line%<*} ENTRY[5]=${tmpline##*>};; ch ) ENTRY[6]=$line;; /d ) ENTRY[7]=$line;; /n ) ENTRY[8]=$line BLOCKDONE=yes;; * ) echo -e "\n\terror: No tag match in block: $BLOCKNO, line: $CLINE\n";; esac # check if BLOCKDONE=yes if [[ $BLOCKDONE == 'yes' ]]; then ((BLOCKNO+=1)) # check if file exists for ((j=0;j<=${#LOCDELTA[@]};j++)); do if [[ ${ENTRY[3]} == ${LOCDELTA[$j]} ]]; then # writexml writexml $NEWFILE fi done # reset block and loop control variables BLOCKDONE=no PATCHINFO=1 fi fi done < $XMLFILE ((CLINE+=1)) echo -ne $FOOTER >> $NEWFILE exit 0 If you don't like the line wrapping here, you can download the script directly from: http://www.3111skyline.com/download/linux/scripts/xmlparse -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday March 26 2009, David C. Rankin wrote:
Anders Johansson wrote:
...
Could you post the xmlparse script?
Anders
Anders,
I would be glad to now. 20 minutes ago I would have been a wee-bit embarrassed. I found the culprit. (ducking...) there was a stray echo. ...
Welcome to the wonderful world of programming.
#!/bin/bash --norc ## ...
It's never a good idea to put full program text in the body of a message. Always include it as an attachment.
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thu, 26 Mar 2009, Randall R Schulz wrote:- <snip>
It's never a good idea to put full program text in the body of a message. Always include it as an attachment.
There's no guarantee that it will stay there is it's included as an attachment. From your headers: X-MIME-Notice: attachments may have been removed from this message Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s openSUSE 10.3 32b | openSUSE 11.0 32b | | openSUSE 10.3 64b | openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 10.3 PPC | RISC OS 3.6 | RISC OS 3.11 | TOS 4.02 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday March 27 2009, David Bolt wrote:
On Thu, 26 Mar 2009, Randall R Schulz wrote:-
<snip>
It's never a good idea to put full program text in the body of a message. Always include it as an attachment.
There's no guarantee that it will stay there is it's included as an attachment. From your headers:
X-MIME-Notice: attachments may have been removed from this message
I don't know what that means or where it originates. but it most certainly was not in what I sent. Attachments survive to the SUSE lists just fine and protect text for the horrid mangling that happens to message body text. Attachments _are_ preferred for any kind of formatted, non-flowed text content and are, of course, mandatory for non-text content.
Regards, David Bolt
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday 27 March 2009 08:42:41 pm Randall R Schulz wrote:
I don't know what that means or where it originates.
Press v and look for X-MIME-Notice: in any message. It si appended by list server as warning that some attachments can be stripped off. -- Regards, Rajko -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday 27 March 2009 08:35:20 pm David Bolt wrote:
On Thu, 26 Mar 2009, Randall R Schulz wrote:-
<snip>
It's never a good idea to put full program text in the body of a message. Always include it as an attachment.
There's no guarantee that it will stay there is it's included as an attachment. From your headers:
X-MIME-Notice: attachments may have been removed from this message
There is always http://pastebin.ca where one can paste text and then the other can edit it. Not ideal for ML as it can happen fun stuff if third. person "helps". -- Regards, Rajko -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Fri, 27 Mar 2009, Rajko M. wrote:-
There is always http://pastebin.ca where one can paste text and then the other can edit it. Not ideal for ML as it can happen fun stuff if third. person "helps".
Another "not ideal for mailing lists" feature is that, by default, posting something there will expire after a period of 30 days. While the default can be overridden, there's the probability that the poster won't, and it won't get "edited" and the expiry time changed by someone else. Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s openSUSE 10.3 32b | openSUSE 11.0 32b | | openSUSE 10.3 64b | openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 10.3 PPC | RISC OS 3.6 | RISC OS 3.11 | TOS 4.02 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
Anders Johansson
-
David Bolt
-
David C. Rankin
-
Rajko M.
-
Randall R Schulz