binary file within a shell script

2008-05-08 Thread Mathieu Prevot
Hi there,

I would like to use one exec file from a shellscript but I would like
it to be incorporated in the same file, like Nvidia do for its FreeBSD
drivers. How can I do this in a convenient way ?

Mathieu
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: binary file within a shell script

2008-05-08 Thread Jille

It's not exactly what you are looking for:
But you could take a look at shar(1).
I don't even know for sure whether it can archive binaries.
shar gives you a shellscript, to which you could prefix your own script,
and when you run it, it'll extract the incorporated file, and you can
exec it :)

-- Jille
(Resend from right email-adres)

Mathieu Prevot wrote:

Hi there,

I would like to use one exec file from a shellscript but I would like
it to be incorporated in the same file, like Nvidia do for its FreeBSD
drivers. How can I do this in a convenient way ?

Mathieu
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]
  


___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: binary file within a shell script

2008-05-08 Thread Dan Nelson
In the last episode (May 08), Mathieu Prevot said:
 Hi there,
 
 I would like to use one exec file from a shellscript but I would like
 it to be incorporated in the same file, like Nvidia do for its FreeBSD
 drivers. How can I do this in a convenient way ?

Take a look at the file generated by /usr/bin/gzexe; that's one way to
do it (basically, determine the number of lines in your shell script,
append your binary file to the end of the script, and use tail to
extract only the binary file to a tempfile).

-- 
Dan Nelson
[EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: binary file within a shell script

2008-05-08 Thread ari edelkind
[EMAIL PROTECTED] wrote:

 I would like to use one exec file from a shellscript but I would like
 it to be incorporated in the same file, like Nvidia do for its FreeBSD
 drivers. How can I do this in a convenient way ?

I haven't looked at nvidia's driver packaging, but you can embed
binaries into shell scripts using uuencode or base64.

Example:

% cat test.sh
#!/bin/ksh

echo *** generating ls...
file=`mktemp /tmp/ls.XX`
[[ $? -eq 0 ]] || exit 1

uudecode -o $lsfile '__EOM__'
^D
% uuencode ls /bin/ls test.sh
% cat test.sh
__EOM__

chmod +x $lsfile
echo *** running $lsfile ...
$lsfile
echo *** cleaning up
rm -f $lsfile
^D


Note that i used single quotes in the here-document initialization, so
there won't be any shell expansion of the uuencoded data.

A few commonly-installed programs that may suit your needs:
  - uuencode / uudecode
  - base64
  - b64
  - openssl base64


If relying on one of the above is infeasible:

You can't portably use inline binary data in a shell script without
preprocessing it (as with one of the above programs), since most shells
can't handle binary zeros; shar(1) fails in this case.  You could,
theoretically, write a small, clever wrapper function to account for the
issue.  You'd also have to ensure that regexp(^__EOM__$) (in the above
example) doesn't exist within the file contents, and note that
excessively long lines may not be handled efficiently by the shell.
You'll need to account for files that do or don't end in a newline,
possibly by always appending an extra newline, then stripping it upon
extraction.  Lastly, you'll need to consider whether you must account
for CR/LF conversion in file transfers or while editing your script.

You probably won't want to deal with all of this, and would be better
off leaving it for out-of-band extraction, such as with dan's gzexe
suggestion.  You'll still need to determine whether CR/LF conversion may
be an issue for you.

ari


___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: binary file within a shell script

2008-05-08 Thread ari edelkind
[EMAIL PROTECTED] wrote:

 echo *** generating ls...
 file=`mktemp /tmp/ls.XX`
 [[ $? -eq 0 ]] || exit 1

Er, s/^file/lsfile/, obviously.

ari

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Running a shell script on becoming the CARP master?

2005-11-28 Thread Max Laier
On Saturday 26 November 2005 16:14, Matthew Hagerty wrote:
 Are there any hooks into CARP to run a shell script when a machine
 becomes the master?  Also, is there a way to force a machine to become
 the master without powering off the current master (for example to do
 maintenance on the current master)?

net/ifstated from ports might be what you are looking for.

-- 
/\  Best regards,  | [EMAIL PROTECTED]
\ /  Max Laier  | ICQ #67774661
 X   http://pf4freebsd.love2party.net/  | [EMAIL PROTECTED]
/ \  ASCII Ribbon Campaign  | Against HTML Mail and News


pgpkEHnQYn8sF.pgp
Description: PGP signature


Running a shell script on becoming the CARP master?

2005-11-26 Thread Matthew Hagerty

Greetings,

Are there any hooks into CARP to run a shell script when a machine 
becomes the master?  Also, is there a way to force a machine to become 
the master without powering off the current master (for example to do 
maintenance on the current master)?


Thanks,
Matthew
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Running a shell script on becoming the CARP master?

2005-11-26 Thread Dominic Marks
On Saturday 26 November 2005 15:14, Matthew Hagerty wrote:
 Greetings,
 
 Are there any hooks into CARP to run a shell script when a machine 
 becomes the master?  Also, is there a way to force a machine to become 
 the master without powering off the current master (for example to do 
 maintenance on the current master)?

I believe there was supposed to be a utility for this sort of thing
but I haven't seen or heard anything about it. In the mean time a
program which read the data could probably be built from the ifconfig
code quite simply. It would be really nice if there were kevent
notifications for CARP events.

 Thanks,
 Matthew
 ___
 freebsd-hackers@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
 To unsubscribe, send any mail to [EMAIL PROTECTED]
 

-- 
Dominic Marks
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Running a shell script on becoming the CARP master?

2005-11-26 Thread David S. Madole

From: Matthew Hagerty [EMAIL PROTECTED]


Are there any hooks into CARP to run a shell script when a machine 
becomes the master?  Also, is there a way to force a machine to become 
the master without powering off the current master (for example to do 
maintenance on the current master)?


I don't know of any way to do the former, but for the latter it's easy 
enough to temporarily adjust the advbase setting higher on the master 
until failover occurs. Set it to at least three times the setting on the 
slave.


Or simply ifconfig down the carp interface on the master.

David

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Running a shell script on becoming the CARP master?

2005-11-26 Thread Dag-Erling Smørgrav
Matthew Hagerty [EMAIL PROTECTED] writes:
 Are there any hooks into CARP to run a shell script when a machine
 becomes the master?

Have you tried using devd to catch the link up / down event on the
carp interface?

DES
-- 
Dag-Erling Smørgrav - [EMAIL PROTECTED]

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Running a shell script on becoming the CARP master?

2005-11-26 Thread Matthew Hagerty

Dag-Erling Smørgrav wrote:


Matthew Hagerty [EMAIL PROTECTED] writes:
 


Are there any hooks into CARP to run a shell script when a machine
becomes the master?
   



Have you tried using devd to catch the link up / down event on the
carp interface?

DES
 



I'm not familiar with devd, but I'll certainly look into it.

Matthew

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Running a shell script on becoming the CARP master?

2005-11-26 Thread Matthew Hagerty

David S. Madole wrote:


From: Matthew Hagerty [EMAIL PROTECTED]



Are there any hooks into CARP to run a shell script when a machine 
becomes the master?  Also, is there a way to force a machine to 
become the master without powering off the current master (for 
example to do maintenance on the current master)?



I don't know of any way to do the former, but for the latter it's easy 
enough to temporarily adjust the advbase setting higher on the master 
until failover occurs. Set it to at least three times the setting on 
the slave.


Or simply ifconfig down the carp interface on the master.

David

Taking the master carp interface down certainly would accomplish the 
task, I just didn't know if there was a more elegant method.  Thanks for 
the info.


Matthew

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Running a shell script on becoming the CARP master?

2005-11-26 Thread Matthew Hagerty

Dominic Marks wrote:


On Saturday 26 November 2005 15:14, Matthew Hagerty wrote:
 


Greetings,

Are there any hooks into CARP to run a shell script when a machine 
becomes the master?  Also, is there a way to force a machine to become 
the master without powering off the current master (for example to do 
maintenance on the current master)?
   



I believe there was supposed to be a utility for this sort of thing
but I haven't seen or heard anything about it. In the mean time a
program which read the data could probably be built from the ifconfig
code quite simply. It would be really nice if there were kevent
notifications for CARP events.

 


Thanks,
Matthew
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]

   



 

I was looking at the ifconfig output and it certainly could be parsed 
for the CARP status I suppose, but it just seemed a little crude and I 
wanted to make sure I was not missing something more obvious.  Do you 
know if the CARP interface is up, available, and stable by the time 
/usr/local/etc/rc.d scripts are run?


Thanks,
Matthew

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Shell script

2000-11-22 Thread petro

I have such script.

# more trafdump
#!/bin/sh -
#   trafdumpCopyright (c)1993 CAD lab
#
#   dump all records to /var/tmp/trafd.$iface
#
# usage: trafdump interfaces...
#
PATH=/usr/local/bin
WHERE_PID=/var/run/trafd.ed0
LOG_FILE=/var/log/traffic.log

if [ $# = 0 ]; then
echo trafdump - dump tcp/udp network data traffic
echo usage: trafdump interfaces...
exit 1
fi

for iface in $*; do
PID_FILE=$WHERE_PID$iface
if [ -f $PID_FILE ]; then
kill -HUP `cat $PID_FILE`
if [ $? = 0 ]; then
echo `date +"%b %e %H:%M:%S"` `hostname -s`
trafdump: \
'('$iface')' signaling to dump  $LOG_FILE
fi
else
echo error: $PID_FILE not found | tee -a $LOG_FILE
fi
done
#

but when I try to start
# ./trafdump -ied0
I receive three errors
I can't understand whereis the errors.
[: not found
[: not found
tee: not found




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Shell script

2000-11-22 Thread void

On Thu, Nov 23, 2000 at 02:30:54AM +0200, petro wrote:
 I have such script.
 
 PATH=/usr/local/bin
[...] 
 if [ $# = 0 ]; then
[...] 
 if [ -f $PID_FILE ]; then
[...] 
 if [ $? = 0 ]; then
[...]
echo error: $PID_FILE not found | tee -a $LOG_FILE

 I receive three errors
 I can't understand whereis the errors.
 [: not found
 [: not found
 tee: not found

$ which [
/bin/[
$ which tee   
/usr/bin/tee

Fix your PATH and all will be well.  And next time, post your question
to [EMAIL PROTECTED]

-- 
 Ben

220 go.ahead.make.my.day ESMTP Postfix


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Shell script

2000-11-22 Thread Tony Fleisher

Your PATH variable (line 8) needs to include /bin, where both tee and [
are located.

Tony.

On Thu, 23 Nov 2000, petro wrote:

 I have such script.
 
 # more trafdump
 #!/bin/sh -
 #   trafdumpCopyright (c)1993 CAD lab
 #
 #   dump all records to /var/tmp/trafd.$iface
 #
 # usage: trafdump interfaces...
 #
 PATH=/usr/local/bin
 WHERE_PID=/var/run/trafd.ed0
 LOG_FILE=/var/log/traffic.log
 
 if [ $# = 0 ]; then
 echo trafdump - dump tcp/udp network data traffic
 echo usage: trafdump interfaces...
 exit 1
 fi
 
 for iface in $*; do
 PID_FILE=$WHERE_PID$iface
 if [ -f $PID_FILE ]; then
 kill -HUP `cat $PID_FILE`
 if [ $? = 0 ]; then
 echo `date +"%b %e %H:%M:%S"` `hostname -s`
 trafdump: \
 '('$iface')' signaling to dump  $LOG_FILE
 fi
 else
 echo error: $PID_FILE not found | tee -a $LOG_FILE
 fi
 done
 #
 
 but when I try to start
 # ./trafdump -ied0
 I receive three errors
 I can't understand whereis the errors.
 [: not found
 [: not found
 tee: not found
 
 
 
 
 To Unsubscribe: send mail to [EMAIL PROTECTED]
 with "unsubscribe freebsd-hackers" in the body of the message
 



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Upper -Lower in shell script

1999-12-17 Thread Alex

This message was sent from Geocrawler.com by "Alex" [EMAIL PROTECTED]
Be sure to reply to that address.

Hello,

I need in my shell script change upper case to 
lower case for characters. Cureently , I call c 
programm from script which do it.
Is anybody did this inside script?

Thank you
Alex

Geocrawler.com - The Knowledge Archive


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Upper -Lower in shell script

1999-12-17 Thread Dan Nelson

In the last episode (Dec 17), Alex said:
 I need in my shell script change upper case to lower case for
 characters. Cureently , I call c programm from script which do it. Is
 anybody did this inside script?

#!/bin/sh
var=MixedCase
lvar=`echo $var | tr A-Z a-z`
echo $lvar

#!/usr/local/bin/zsh
var=MixedCase
lvar=${var:l}
echo $lvar

-- 
Dan Nelson
[EMAIL PROTECTED]


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Upper -Lower in shell script

1999-12-17 Thread Chris Costello

On Fri, Dec 17, 1999, Alex wrote:
 I need in my shell script change upper case to 
 lower case for characters. Cureently , I call c 
 programm from script which do it.
 Is anybody did this inside script?

   Shells such as ksh (both PDKSH and ATT KSH, available in
ports, support this) and bash have a typeset command.  To convert
something to all upper-case is surprisingly easy:

typeset -u variable

   Example:

$ typeset -u f
$ f=abc
$ echo $f
ABC

-- 
|Chris Costello [EMAIL PROTECTED]
|Beware of programmers who carry screwdrivers.  - Leonard Brandwein
`--


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Upper -Lower in shell script

1999-12-17 Thread Chris Costello

On Fri, Dec 17, 1999, Alex wrote:
 I need in my shell script change upper case to 
 lower case for characters. Cureently , I call c 
 programm from script which do it.
 Is anybody did this inside script?

   Oops.  That should be typeset -l.

$ typeset -l var
$ var=ABC
$ echo $var
abc

-- 
|Chris Costello [EMAIL PROTECTED]
|Random access is the optimum of the mass storages.
`--


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Help with exit status in shell script

1999-08-28 Thread Oliver Fromme

Roger Hardiman wrote in list.freebsd-hackers:
  There is a bug in the PicoBSD build shell script in and I have no idea
  how to fix it. As a result, build errors are not caught.
  It is all to do with Exit Status of programs called from a shell script.
  Please help.
  
  The code fragment from /usr/src/release/picobsd/build/build is
 ./stage1 21 | tee stage1.out
  if [ "X$?" != "X0" ] ; then 
  echo "^G"
  echo "- ERROR in \"${i}\" script. Aborting the build process."
  exit 10
  fi
  
  Build calls Stage1. Stage1 will return with an error code in some cases
  and we want to trap this and halt the Build script.
  
 ./stage1 21 | tee stage1.out
  if [ "X$?" != "X0" ] ; then 
  
  Normally, $? will return the Exit Status of the last executed program.
  However, due to the pipe through Tee, the Exit Status I get is the
  exit status of Tee and not the exit status of the Stage1 script.
  
  I still want to output the stage1 script to screen and a log file.
  How can I do this and preserve the exit status for the Build script.

There are several solutions, but all of them are somewhat
ugly...

One approach would be to use a named pipe, run stage1 in the
background and then wait for it, grabbing its exit status:

   FIFO=/tmp/`basename $0`.$$.fifo
   trap "rm -f $FIFO" 1 2 15
   mkfifo $FIFO
   ./stage1  $FIFO 21 
   STAGE1PID=$!
   tee  $FIFO stage1.out
   wait $STAGE1PID
   if [ $? != 0 ]; then
   ...
   rm -f $FIFO

Maybe it's possible to open a new shell descriptor (e.g. 3)
instead of a named pipe, but I haven't tried this.

Another way would be to put the exit code into a temporary
file, like this:

   trap "rm -f stage1.result" 1 2 15
   (
   ./stage1 21
   echo $?  stage1.result
   ) | tee stage1.out
   if [ `cat stage1.result` != 0 ]; then
   ...
   rm -f stage1.result

Regards
   Oliver

-- 
Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
(Info: finger userinfo:[EMAIL PROTECTED])

"In jedem Stück Kohle wartet ein Diamant auf seine Geburt"
 (Terry Pratchett)


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Help with exit status in shell script

1999-08-28 Thread Luigi Rizzo

 Hi,
 There is a bug in the PicoBSD build shell script in and I have no idea
 how to fix it. As a result, build errors are not caught.
 It is all to do with Exit Status of programs called from a shell script.
 Please help.
 
 The code fragment from /usr/src/release/picobsd/build/build is
./stage1 21 | tee stage1.out

given that there is, in the same script, a "fail" procedure to handle
such cases, i believe you could do something like

(./stage1 21 || fail $? stage1_failed ) | tee stage1.out

(where the $? has nothing special, just that the "fail" procedre
expects the errcode as first argument).
If it turns out to be problematic, for 3.3R you could as well remove
the "tee", after all it was just there for debugging.

cheers
luigi


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Help with exit status in shell script

1999-08-28 Thread Roger Hardiman
Hi,
There is a bug in the PicoBSD build shell script in and I have no idea
how to fix it. As a result, build errors are not caught.
It is all to do with Exit Status of programs called from a shell script.
Please help.

The code fragment from /usr/src/release/picobsd/build/build is
   ./stage1 21 | tee stage1.out
if [ X$? != X0 ] ; then 
echo ^G
echo - ERROR in \${i}\ script. Aborting the build process.
exit 10
fi

Build calls Stage1. Stage1 will return with an error code in some cases
and we want to trap this and halt the Build script.

   ./stage1 21 | tee stage1.out
if [ X$? != X0 ] ; then 

Normally, $? will return the Exit Status of the last executed program.
However, due to the pipe through Tee, the Exit Status I get is the
exit status of Tee and not the exit status of the Stage1 script.

I still want to output the stage1 script to screen and a log file.
How can I do this and preserve the exit status for the Build script.

Thanks
Roger
--
Roger Hardiman
ro...@freebsd.org


To Unsubscribe: send mail to majord...@freebsd.org
with unsubscribe freebsd-hackers in the body of the message



Re: Help with exit status in shell script

1999-08-28 Thread Oliver Fromme
Roger Hardiman wrote in list.freebsd-hackers:
  There is a bug in the PicoBSD build shell script in and I have no idea
  how to fix it. As a result, build errors are not caught.
  It is all to do with Exit Status of programs called from a shell script.
  Please help.
  
  The code fragment from /usr/src/release/picobsd/build/build is
 ./stage1 21 | tee stage1.out
  if [ X$? != X0 ] ; then 
  echo ^G
  echo - ERROR in \${i}\ script. Aborting the build process.
  exit 10
  fi
  
  Build calls Stage1. Stage1 will return with an error code in some cases
  and we want to trap this and halt the Build script.
  
 ./stage1 21 | tee stage1.out
  if [ X$? != X0 ] ; then 
  
  Normally, $? will return the Exit Status of the last executed program.
  However, due to the pipe through Tee, the Exit Status I get is the
  exit status of Tee and not the exit status of the Stage1 script.
  
  I still want to output the stage1 script to screen and a log file.
  How can I do this and preserve the exit status for the Build script.

There are several solutions, but all of them are somewhat
ugly...

One approach would be to use a named pipe, run stage1 in the
background and then wait for it, grabbing its exit status:

   FIFO=/tmp/`basename $0`.$$.fifo
   trap rm -f $FIFO 1 2 15
   mkfifo $FIFO
   ./stage1  $FIFO 21 
   STAGE1PID=$!
   tee  $FIFO stage1.out
   wait $STAGE1PID
   if [ $? != 0 ]; then
   ...
   rm -f $FIFO

Maybe it's possible to open a new shell descriptor (e.g. 3)
instead of a named pipe, but I haven't tried this.

Another way would be to put the exit code into a temporary
file, like this:

   trap rm -f stage1.result 1 2 15
   (
   ./stage1 21
   echo $?  stage1.result
   ) | tee stage1.out
   if [ `cat stage1.result` != 0 ]; then
   ...
   rm -f stage1.result

Regards
   Oliver

-- 
Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
(Info: finger userinfo:o...@dorifer.heim3.tu-clausthal.de)

In jedem Stück Kohle wartet ein Diamant auf seine Geburt
 (Terry Pratchett)


To Unsubscribe: send mail to majord...@freebsd.org
with unsubscribe freebsd-hackers in the body of the message



Re: Help with exit status in shell script

1999-08-28 Thread Ben Smithurst
Roger Hardiman wrote:

 Build calls Stage1. Stage1 will return with an error code in some cases
 and we want to trap this and halt the Build script.
 
./stage1 21 | tee stage1.out
 if [ X$? != X0 ] ; then 
 
 Normally, $? will return the Exit Status of the last executed program.
 However, due to the pipe through Tee, the Exit Status I get is the
 exit status of Tee and not the exit status of the Stage1 script.
 
 I still want to output the stage1 script to screen and a log file.
 How can I do this and preserve the exit status for the Build script.

There's a bit about this in the Csh Programming Considered Harmful
document, showing how easy it is in the  Bourne shel:

   Consider the pipeline:
   A | B | C
   You want to know the status of C, well, that's easy: it's in $?, or
   $status in csh. But if you want it from A, you're out of luck -- if
   you're in the csh, that is. In the Bourne shell, you can get it,
   although doing so is a bit tricky. Here's something I had to do where
   I ran dd's stderr into a grep -v pipe to get rid of the records in/out
   noise, but had to return the dd's exit status, not the grep's:
   device=/dev/rmt8
   dd_noise='^[0-9]+\+[0-9]+ records (in|out)$'
   exec 31
   status=`((dd if=$device ibs=64k 21 13 3- 4-; echo $? 4) |
   egrep -v $dd_noise 12 3- 4-) 41`
   exit $status;

See http://www-uxsup.csx.cam.ac.uk/csh.html for the rest.

so

exec 31
exit_code=`((./stage1 21 13 3- 4-; echo $? 4) |
tee stage1.out 12 3- 4-) 41`
exec 3-

or something, should get it for you. I used `exit_code' rather than
`status' because `$status' is read-only in zsh, but that shouldn't be a
problem for plain old sh. You'd better add some comments explaining just
what it does :-)

-- 
Ben Smithurst| PGP: 0x99392F7D
b...@scientia.demon.co.uk |   key available from keyservers and
 |   ben+...@scientia.demon.co.uk


To Unsubscribe: send mail to majord...@freebsd.org
with unsubscribe freebsd-hackers in the body of the message



Re: Help with exit status in shell script

1999-08-28 Thread Luigi Rizzo
 Hi,
 There is a bug in the PicoBSD build shell script in and I have no idea
 how to fix it. As a result, build errors are not caught.
 It is all to do with Exit Status of programs called from a shell script.
 Please help.
 
 The code fragment from /usr/src/release/picobsd/build/build is
./stage1 21 | tee stage1.out

given that there is, in the same script, a fail procedure to handle
such cases, i believe you could do something like

(./stage1 21 || fail $? stage1_failed ) | tee stage1.out

(where the $? has nothing special, just that the fail procedre
expects the errcode as first argument).
If it turns out to be problematic, for 3.3R you could as well remove
the tee, after all it was just there for debugging.

cheers
luigi


To Unsubscribe: send mail to majord...@freebsd.org
with unsubscribe freebsd-hackers in the body of the message