String handling in sh

String handling in sh

Post by CDI » Fri, 08 Nov 1996 04:00:00




Quote:> I have a script fo running backups , and I grab the filesystems I need
> like this:

> #!/bin/sh
> .
> .
> hold=`df -k | grep /dev/dsk | awk '{print $1}'`
> .

> The value of ${hold} is then a single line of space separated device names
> like this:

> echo ${hold}  will give the following:

> /dev/dsk50 /dev/dsk53 /dev/dsk37 /dev/dsk38 /dev/dsk29

> I then go on to do the dumps like this:

> for filesystem in ${hold}
> do
>   dump 0dsbfu 54000 6000 128 /dev/rmt0 ${filesystem}
> done

> All is well, but I need to selectively edit the filesystems in the list,
> and only dump some of them (we have some raid devices which do not need backup
> and they total 3/4 terabyte, so I'd be backing up forever <g>).

> What sh commands can I use to get some of the values out of the list
> contained in ${hold} ?

Change your awk command to look something like this:
    awk '$1 ~ /dsk50|dsk53|dsk29/{print $1}'

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    Cal Dunigan                       My opinions *ARE* the company's

    Consulting, Modeling, Training
//////////////////////////////////////////////////////////////////////

 
 
 

String handling in sh

Post by Chuck Campbe » Sat, 09 Nov 1996 04:00:00


I have a script fo running backups , and I grab the filesystems I need
like this:

#!/bin/sh
.
.
hold=`df -k | grep /dev/dsk | awk '{print $1}'`
.

The value of ${hold} is then a single line of space separated device names
like this:

echo ${hold}  will give the following:

/dev/dsk50 /dev/dsk53 /dev/dsk37 /dev/dsk38 /dev/dsk29

I then go on to do the dumps like this:

for filesystem in ${hold}
do
  dump 0dsbfu 54000 6000 128 /dev/rmt0 ${filesystem}
done

All is well, but I need to selectively edit the filesystems in the list,
and only dump some of them (we have some raid devices which do not need backup
and they total 3/4 terabyte, so I'd be backing up forever <g>).

What sh commands can I use to get some of the values out of the list
contained in ${hold} ?

thanks in advance,
-chuck

--
ACCEL Services, Inc.| Specialists in Gravity, Magnetics |  1(713)993-0671 ph.
1980 Post Oak Blvd. |   and Integrated Interpretation   |  1(713)960-1157 fax
    Suite 2050      |                                   |

                    |  President & Senior Geoscientist  |

     "Integration means more than having all the maps at the same scale!"

 
 
 

String handling in sh

Post by Per Kistle » Sat, 09 Nov 1996 04:00:00


Hi

There are many ways to rid of the superflous terms:

For instance you could ask in the for loop with:

(Use ksh if you have it!)

#!/usr/bin/ksh

for f in $hold;do

    if [[ $f != "/dev/dskXX" && \
          $f != "/dev/dskYY" && \
          $f != "/dev/dskZZ" ]];then

              dump......$f
    fi
done

or you may explicitely remove it with if it's only one:

newhold=`echo $hold|sed -e 's#/dev/dsk38##'`

These are just ideas. There are many more ways. Only if you need
cat, then you get a mail from randal schwarz about a usless use
of cat.

Fur such matters mail me anytime, I like the shells:-))

Bye, Per.
--

Per Kistler, Zuerich, Switzerland.

http://www.micro.biol.ethz.ch/~pkistler
----------------------------------------------------------------------

 
 
 

String handling in sh

Post by Bill Marc » Sat, 09 Nov 1996 04:00:00



>I have a script fo running backups , and I grab the filesystems I need
>like this:

>#!/bin/sh
>.
>.
>hold=`df -k | grep /dev/dsk | awk '{print $1}'`
>.

>The value of ${hold} is then a single line of space separated device names
>like this:

>echo ${hold}  will give the following:

>/dev/dsk50 /dev/dsk53 /dev/dsk37 /dev/dsk38 /dev/dsk29

>I then go on to do the dumps like this:

>for filesystem in ${hold}
>do
>  dump 0dsbfu 54000 6000 128 /dev/rmt0 ${filesystem}
>done

>All is well, but I need to selectively edit the filesystems in the list,
>and only dump some of them (we have some raid devices which do not need backup
>and they total 3/4 terabyte, so I'd be backing up forever <g>).

>What sh commands can I use to get some of the values out of the list
>contained in ${hold} ?

hold=`df -k | grep /dev/dsk | awk '$1 !~ /raid/ {print $1}'`
(change /raid/ to whatever sequence of characters would identify a raid
device)

>thanks in advance,
>-chuck

>--
>ACCEL Services, Inc.| Specialists in Gravity, Magnetics |  1(713)993-0671 ph.
>1980 Post Oak Blvd. |   and Integrated Interpretation   |  1(713)960-1157 fax
>    Suite 2050      |                                   |

>                    |  President & Senior Geoscientist  |

>     "Integration means more than having all the maps at the same scale!"

--

"You can pay Uncle Sam with the overtime
 Is that all you get for your money?" --Billy Joel
 
 
 

1. Execute a sh script under perl and sh: sh script; perl script?

I can execute the following perl scripts under either shell or Perl
====

        if 0;
[perl scripts ...]
====
i.e.
sh script
perl script

How do I execute a sh script under either shell or Perl
simililar to what shown above?

Thanks.
--
Michael Wang

http://www.mindspring.com/~mwang    

2. lilo

3. Q: sh: Can I quote '"' in a double quoted string?

4. How to add SCSI disk to x86?

5. Process group handling in /bin/sh

6. select() for a client

7. /bin/sh read & echo strings like "c:\tmp\foovar"

8. UUCP on SCO

9. count the /s from a string in sh

10. string length under sh

11. in 'getopt()', how to handle multiple options in the 'optarg' string?

12. possible error in variable handling by sh (Solaris 8)

13. string parsing in sh