- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Problem replacing text in a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2002 03:00 PM
12-05-2002 03:00 PM
Somthing along the lines of cat /etc/fstab |grep $APPHOME |awk '{ print $1 }' sed ?????
How would I insert the "r" into /dev/vg01/lvol6, sometimes clients use different naming conventions ... /dev/vg02/appname
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2002 03:09 PM
12-05-2002 03:09 PM
Re: Problem replacing text in a script
....
...
for ENTRY in $(grep $APPHOME /etc/fstab|awk '{print $1}')
do
LVOL=$(echo $ENTRY|awk '{FS="/";print $4}')
RLVOL=$(echo $ENTRY|sed 's/'$LVOL'/r'$LVOL'/')
echo $RLVOL
done
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2002 03:48 PM
12-05-2002 03:48 PM
Re: Problem replacing text in a script
LVOL=`cat /etc/fstab|grep $APPHOME|awk -F / '{print $4}'`
VG=`cat /etc/fstab|grep $APPHOME|awk -F / '{print $3}'`
And when you want to substitute with 'r' you can do it
RLVOL=/dev/${VG}/r${LVOL}
cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2002 12:37 AM
12-06-2002 12:37 AM
Re: Problem replacing text in a script
you could use the korn shell's built-in functions for string handling, e.g.:
#!/usr/bin/sh
APPHOME=$1
cat /etc/fstab | grep $APPHOME | while read line
do
LVOL=`echo $line | awk '{print $1}'`
ENDING=`basename $LVOL`
BEGINNING="${LVOL%%$ENDING}"
echo ${BEGINNING}r${ENDING}
done
~
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2002 12:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2002 05:50 AM
12-09-2002 05:50 AM
Re: Problem replacing text in a script
bdf gives you the name of the lv your application is using.
I prefer using bdf
#[SAVE]> bdf /tmp/test/
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol4 1024000 40785 921815 4% /tmp
The following command should, (though there might be tyops: I don't have access to my system fron here), give you the correct answer:
bdf $APPHOME |grep /dev/ |sed 's!(\^[^ ]+/\)!\1r!'|awk '{print $1}'
The bdf part will give you the logical volume on which your application resides, the grep will ensure that only the relevant line is printed, the sed will find the longest string containing a '/' since the begining of the line, and add 'r'after it, and the awk will print only the first argument...
I won't promise that the command is _fast_, though ;-)
Cheers,
Fran??ois-Xavier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2002 06:01 AM
12-09-2002 06:01 AM
Re: Problem replacing text in a script
/dev/vg00/lvol3 / vxfs delaylog 0 1
/dev/vg00/lvol1 /stand hfs defaults 0 1
/dev/vg00/tmp /tmp vxfs rw,suid,largefiles,delaylog,datainlog 0 2
/dev/vg00/lvol7 /usr vxfs delaylog 0 2
/dev/vg00/var /var vxfs delaylog 0 2
/dev/vg00/opt /opt vxfs delaylog 0 2
/dev/vg00/home /home vxfs delaylog 0 2
/dev/vg00/u /u vxfs rw,suid,largefiles,delaylog,datainlog 0 2
/dev/vg00/pro /pro vxfs rw,suid,largefiles,delaylog,datainlog 0 2
/dev/vg00/data /data vxfs rw,suid,largefiles,delaylog,datainlog 0 2
/dev/vg00/wrk /wrk vxfs rw,suid,largefiles,delaylog,datainlog 0 2
/dev/cd0 /cdrom cdfs ro,rr,noauto 0 0
a5:/ 109 # echo $APPHOME
/pro
a5:/ 110 # perl -nle'/$ENV{APPHOME}/&&s:\s.*::&&s:vg\d+/:$&r:&&print' /etc/fstab
/dev/vg00/rpro
a5:/ 111 #
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2002 06:04 AM
12-09-2002 06:04 AM
Re: Problem replacing text in a script
I don't know why I insisted on using awk when sed is enough for the job...
Let's try doing it right this time:
bdf $APPHOME |grep /dev/ |sed 's!(\^[^ ]+/\)(\[^ ]+\).+!\1r\2!'
- ^[^ ]+/ should give you the basename of your logical volume,
- [^ ]+ should give you the logical volume name,
- the .+ is there to engulf all the rest of the line
Please remember that this is untested, as I don't have access to my platform. It should be near the mark, though...
Cheers,
Fran??ois-Xavier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2002 06:13 AM
12-09-2002 06:13 AM
Re: Problem replacing text in a script
Enjoy your holidays!
Gus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2002 09:16 AM
12-09-2002 09:16 AM
Re: Problem replacing text in a script
It actually uses sed btw.
Steve
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2002 09:24 AM
12-09-2002 09:24 AM
Re: Problem replacing text in a script
Never use this, not even as an example.
And *if* you need using perl4, at least add -w to the command line.
When converting this to perl5, start with something like
#!/usr/local/bin/perl
use strict;
use warnings;
use File::Find;
use Sys::Hostname;
:
:
: