Sponsored Content
Top Forums Shell Programming and Scripting cmd || echo "something" - doesn't exit uppon error Post 302579091 by radoulov on Sunday 4th of December 2011 02:37:54 PM
Old 12-04-2011
This should do what you want:

Code:
for i in ad0 ad1; do

  gpart create -s gpt "$i" || {
    printf >&2 'Cannot create GPT partition on "%s". Exiting ...\n' "$i"
    exit 1
    }
  
  gpart add -s 128 -t freebsd-boot "$i" || {
    printf >&2 'Cannot add freebsd-boot partition on "%s". Exiting ...\n' "$i"
    exit 1
    }
    
  gpart add -s 4G -t freebsd-swap -l swap "$i" || {
    printf >&2 'Cannot add freebsd-swap partition to "%s". Exiting ...\n'
    exit 1
    }
    
  gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 "$i" || {
    printf >&2 'Cannot add bootcode to "%s". Exiting ...\n' "$i"
    exit 1
    }
    
done

Something like this would be even better:

Code:
die() {
  [ -n "$1" ] &&
    printf >&2 '%s\n' "$1"
  exit 1
  }

for i in ad0 ad1; do

  gpart create -s gpt "$i" || 
    die "Cannot create GPT partition on $i. Exiting ..." 
  
  gpart add -s 128 -t freebsd-boot "$i" || 
    die "Cannot add freebsd-boot partition on $i. Exiting ..."
    
  gpart add -s 4G -t freebsd-swap -l swap "$i" || 
    die "Cannot add freebsd-swap partition to $i. Exiting ..."

  gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 "$i" || 
    die "Cannot add bootcode to "%s". Exiting ..."
    
done

You may need to hide the errors in a logfile, given that you want to handle the exceptions:

Code:
_errlog=${0##*/}_error.log

die() {
  [ -n "$1" ] &&
    printf >&2 '%s\n' "$1"
  exit 1
  }

for i in ad0 ad1; do

  gpart create -s gpt "$i" 2> "$_errlog" || 
    die "Cannot create GPT partition on $i. Exiting ..." 
  
  gpart add -s 128 -t freebsd-boot "$i" 2> "$_errlog" || 
    die "Cannot add freebsd-boot partition on $i. Exiting ..."
    
  gpart add -s 4G -t freebsd-swap -l swap "$i" 2> "$_errlog" || 
    die "Cannot add freebsd-swap partition to $i. Exiting ..."

  gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 "$i" 2> "$_errlog" || 
    die "Cannot add bootcode to "%s". Exiting ..."
    
done


Last edited by radoulov; 12-04-2011 at 03:46 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

assign shell var output of cmd "wc"

how do I feed output of "wc" to a shell script variable "countBcp"? (2 Replies)
Discussion started by: devy
2 Replies

2. Shell Programming and Scripting

Need help on use of "cmd" command in net::Telnet module in PERL

in "cmd" command i want to copy the ouput of the command excuted to a particular file in a directory. How to do this..?? Ex : $telnet->cmd(String => 'allip:acl=a1;',Prompt => '/</'); i want to copy o/p of the command "allip:acl=a1;" in a log file in a particular directory. Plz suggest.. (1 Reply)
Discussion started by: sudhakaryadav
1 Replies

3. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

4. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

5. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

8. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

9. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 12:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy