1834009 Members
1944 Online
110063 Solutions
New Discussion

script

 
Hari Prasad S.R
Occasional Contributor

script

Hi,

Below is my file-system output I want to know how find and replace from /osxfiles to /osx using sed editor.

Filesystem 1k-blocks Used Available Used% Mounted on
/dev/disk9 3121344 1314624 1806720 42% /osxfiles
17 REPLIES 17
Rasheed Tamton
Honored Contributor

Re: script

Hi,

I do not know whether I got your question correctly. But from the first look, I think you want as below:

bdf| sed 's/osxfiles/osx/'
Hari Prasad S.R
Occasional Contributor

Re: script

i want to kknow how exactly we can define /osxfiles [/ needs to be included],
as i have one more like

/sap1/sap to /usr/sap

but i have some of the file systems like /sap1/opt , /sap1/usr.

if i use that other file-systems will also get effected.


regards,
Hari
Sandman!
Honored Contributor

Re: script

Not sure I understand but it would help if you could clarify by giving an example.

~thanks
Rasheed Tamton
Honored Contributor

Re: script

Just give example:

Like
present status:
osxfile
sap

I need as:
osx
usr/sap, etc.

Unless you let us know exactly what you want; it will delay you get a correct solution.

Regards.
Tor-Arne Nostdal
Trusted Contributor

Re: script

Hard to see what you're actually up to. This is why the answers is vague. A more direct question could give more accurate answer.

Here's some general comments, but if you're not confident with what you're doing you should be careful.
-------

You have a mountpoint named /osxfiles

You should not try to change the name of this directory as long as the filesystem is mounted.

Create a new directory named osx
Make sure there is no process using the /osxfiles filesystem.
Unmount the filesystem currently mounted on /osxfiles. Then mount it on the new mountpoint(directory) named osx.

mkdir /osx
umount /osxfiles
cp -p /etc/fstab /etc/fstab.old
cat /etc/fstab | sed 's/osxfiles/osx/g' > /etc/fstab.new
# Inspect the /etc/fstab.new
more /etc/fstab.new
# If file is ok, make it the active one
cat /etc/fstab.new > /etc/fstab
mount /osx

Find files with string 'osxfiles':
find / -type f -print | grep -l '/osxfiles'
NB! This will search through ALL files in your system and report the filename on files containg string '/osxfiles'

To change with sed the string osxfiles into osx in a file you do it like this:
cat myfile | sed 's/osxfiles/osx/g' | > /tmp/myfile.tmp
cat /tmp/myfile.tmp > myfile

Search and replace can also be done in 'vi' similarily as with sed.
example:
vi myfile
:s/osxfiles/osx/g
:wq

/Tor-Arne
I'm trying to become President of the state I'm in...
spex
Honored Contributor

Re: script

Hello,

For each mountpoint you wish to migrate, first create a directory to contain the filesystem, then modify the appropriate entries in /etc/fstab. Then 'umount ', and 'mount -a' to mount all filesystems. Alternatively, if you wish to manually mount the filesystems, make sure you mount parent filesytems before their children (e.g. /var before /var/tmp).

PCS
Hari Prasad S.R
Occasional Contributor

Re: script

Hi,

Below is the output of the dbf i just wanted fire backup from this server excluding /,/stand and /tmp. I wanted to do this only with sed editor bcoz same script i will
put in some 150 servers and the problem is if i give bdf command it will show many
file-systems and backup should happen for all the file-systems excluding / /stand and /tmp.

$ bdf
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 2097152 1494496 598520 71% /
/dev/vg00/lvol1 295024 73200 192320 28% /stand
/dev/vg00/lvol8 2826240 1918640 901648 68% /var
/dev/vg00/lvol7 1056768 1003352 53144 95% /usr
/dev/vg00/lvol4 77824 34904 42920 45% /tmp
/dev/vg01/lvol1 18530304 16975068 1530996 92% /oracle
/dev/vg00/lvol6 8245248 5311432 2910928 65% /opt
/dev/vg00/lvol5 20480 10432 10024 51% /home

so can any one tell me how to exclude these file-systems.

currently i have arrived only till. like below

$ bdf | awk '{print $6}'
Mounted
/
/stand
/var
/usr
/tmp
/oracle
/opt
/home
Rasheed Tamton
Honored Contributor

Re: script

Hi,

That means you want to exclude /stand and /tmp from the bdf output - possibly I assume that you are trying a fbackup with a graph file.

bdf|sed 1d| awk '{print $6}'|grep -Ev 'stand|tmp'

Rasheed Tamton
Honored Contributor

Re: script

Hi Hari,

If you want to use only awk; then:


bdf|sed 1d| awk ' $6 !~ /(stand|tmp)/ {print $6}'

Rgds,
Rasheed Tamton.
Tor-Arne Nostdal
Trusted Contributor

Re: script

Creating a list of FS's to know what to backup...

Remember that as a sysadmin one of your 1'st priorities should be to have a good and reliable backup procedure...
If you are uncomfortable with scripting you should be careful to put to much logic into such. KISS - Keep It Simple Stupid.
It is better with a good manual procedure than a unreliable automatic procedure.

You should be carefule with using the bdf output as a list for filesystems to do backup of.

The list might be wrong if you have long path/filenames and/or if you have nfs mounted filesystems.
-----
An alternative to using 'bdf' is to use 'df'
See 'man df' and options like '-l'
This command is also more portable (to f.ex. Linux)
-----
Pls. read this link also

http://forums1.itrc.hp.com/service/forums/helptips.do?#33

/Tor-Arne
I'm trying to become President of the state I'm in...
Hari Prasad S.R
Occasional Contributor

Re: script

Hi,
Sorry for the delay.

Actually i am working in aix environment from i need to take backup of rootdump of more than some 150 servers. Below is the output of the rootvg.

# lsvg -l rootvg
rootvg:
LV NAME TYPE LPs PPs PVs LV STATE MOUNT POINT
hd5 boot 1 2 2 closed/syncd N/A
hd6 paging 8 16 2 open/syncd N/A
hd8 jfs2log 1 2 2 open/syncd N/A
hd4 jfs2 5 10 2 open/syncd /
hd2 jfs2 36 72 2 open/syncd /usr
hd9var jfs2 16 32 2 open/syncd /var
hd3 jfs2 16 32 2 open/syncd /tmp
hd1 jfs2 1 2 2 open/syncd /home
hd10opt jfs2 1 2 2 open/syncd /opt
legato_lv jfs2 160 320 2 open/syncd /legato
paging00 paging 32 32 1 open/syncd N/A
paging01 paging 32 32 1 open/syncd N/A
user_lv jfs2 6 6 1 closed/syncd /users
backup_lv jfs2 160 160 1 open/syncd /backup
esm_lv jfs2 4 8 2 open/syncd /usr/esm

i need to display those file-system except below
/, /var,/usr,/tmp,/opt and /home

i had comeup with below script.

lsvg -l rootvg | awk '{print $7}' | egrep -v "N/A|L" | sed '/^$/d' | egrep -vx "/|/usr|/var|/tmp|/home|/opt"

output will be displayed as below.

/legato , /users, /backup and /usr/esm

but i need sed script instead of egrep. can anyone helpme on this.

regards
hari
Tor-Arne Nostdal
Trusted Contributor

Re: script

Hi Hari
It is difficult to understand your problem...
What is the problem with 'egrep' versus 'sed' ?
- grep/egrep is used to search for a pattern
- sed is used for search and change the pattern
What is it that you want to do?

1) You want to list the filesystems on the root volume group
lsvg -l rootvg
2) You want to skip
- boot, swap(paging), N/A filesystems
- and the filesystems /, /usr, /var, /tmp, /home and /opt
3) You want to do this on "more than 150 servers"

Questions:
a) Do you have limitations on which commands is available?
ref. "i need sed instead of egrep"
b) Do you need to change the output?
ref. "i need sed instead of egrep"
- if so... then into what?
c)How should the output format be?
example:
/legato
/users
/backup
/usr/esm
or
/legato, /users, /backup, /usr/esm

d) Do you want to remotely execute your commands?
... or why do you mention 150 servers?
e) What kind of backup program are you using?
standard unix like dump/rdump, tar or similare or a separate backup software.
You seam to have Legato installed so I can't see your problem.

hmmm... it's hard to see what we should help you with.

P.S.
It might be difficult to get help/attention if you don't assign points (see URL)

/2r
I'm trying to become President of the state I'm in...
Dennis Handly
Acclaimed Contributor

Re: script

>but i need sed script instead of egrep.

If your problem is that you don't have egrep, you can replace it by grep with multiple -e instead. Use:
$ grep -v -e N/A -e L

(Note the "L" above will exclude any file system with "L", do you really want that?)

>lsvg -l rootvg | awk '{print $7}' | egrep -v "N/A|L" | sed '/^$/d' | egrep -vx "/|/usr|/var|/tmp|/home|/opt"

And replace the last egrep with:
$ grep -vx -e / -e /usr -e /var -e /tmp -e /home -e /opt

And as Tor-Arne asks, there are other issues with what you want with the exact output format.
Sandman!
Honored Contributor

Re: script

imho how about doing it all within a single awk construct w/o sed or (e)grep i.e.

lsvg -l rootvg | awk '
NR>2 && $NF!="N/A" && $NF!="/" &&
$NF!="/var" && $NF!="/opt" &&
$NF!="/usr" && $NF!="/tmp" &&
$NF!="/home" {print $NF}'
Tor-Arne Nostdal
Trusted Contributor

Re: script

Nice awk construct Sandman :-). I expected a such one to arrive, but I don't believe this is Hari's only problem...

1'st posting: find and replace output from 'osxfiles' to 'osx'
- if you want to backup the /osxfiles why do you want to change the output?

2'nd posting: hmm...
/sap1/sap to /usr/sap
does he really want to substitute?
or does he want to find it?

3'rd posting: Output from bdf excluding /, /tmp and /stand

4'th posting: "need sed script"
But in this posting it is mentioned a bit more about the intention.
"need to take backup of rootdump"
this explains also the 'lsvg -l rootvg' command.
Hari has also skipped using the bdf, but here there is more filesystems excluded (/usr, /var, /home)

If I should pick a guess I would say that Hari need (Hari - please confirm if this is right): "A command to output the local filesystems defined on rootvg which he need to backup"

This is all filesystems except:
boot, swap(paging), N/A filesystems
and the filesystems /, /usr, /var, /tmp, /home and /opt

So far the command 'lsvg -l rootvg' combined with Sandman's awk should be ok.

But, should the filesystems be listed horisontal or vertical, with or without comma?
Is this the solution, perhaps only with some small adjustment on output/layout?

-------------
A more complicated Scenario:
Or could the intention be to list/backup all "local filesystems" defined on internal disks (i.e. not filesystems defined on SAN). And to complicate it... that there is created more than 1 volume group and with no specific naming convention.
Server Local-VG SAN-VG
Host1 rootvg
Host2 rootvg, vg01 vgsan01
Host3 vgroot vg01, vg02
With such a scenario Hari would need a bit more than an awk/grep/sed...

Hari - please try to clearify what you need.

/2r
I'm trying to become President of the state I'm in...
Dennis Handly
Acclaimed Contributor

Re: script

>Tor-Arne: should the filesystems be listed horisontal or vertical, with or without comma?

Horizontal vs vertical can be done by a simple:
$ ... $(< file )

Rasheed Tamton
Honored Contributor

Re: script

Hi Har,

If your LV Name ($1) is consistent across the systems, you can do select the pattern on it as below:

lsvg -l rootvg |awk ' $1 ~ /(legato|user|backup|esm)/ {print $NF}'

or more specific
lsvg -l rootvg |awk ' $1 ~ /(legato_lv|user_lv|backup_lv|esm_lv)/ {print $NF}'

If you want to get all in one line - use tr

lsvg -l rootvg |awk ' $1 ~ /(legato_lv|user_lv|backup_lv|esm_lv)/ {print $NF}'|tr "\n" " "

Regards,
Rasheed Tamton.