- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Advanced scripting challege
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
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
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
02-24-2003 12:27 PM
02-24-2003 12:27 PM
I'd be extremely grateful and would be happy to share the full script if anyone is interested.
I have been working on a posix shell script that collects filesystem and volume group info on server which I can then use to duplicate the volume groups, LV's, filesystems structure on a new server. This will be used at my Disaster Recovery site to quickly build the external volume groups and filesystems after the Ignite Recovery.
I've build a script to provide the following output. The numbers represent number of disk devices in each VG.
vg10_disk_list 0 1 2 3
vg01_disk_list 4 5 6 7
vg46_disk_list 8 9 10 11 12
I initialized an array with each member being a disk device:
print "${dsks[0]}"
/dev/dsk/c1t7d3
print "${dsks[1]}"
/dev/dsk/c1t7d4
etc...
Now all I need to do, and the challenge I present to you is:
Provide syntax to change the following:
FROM:
vg10_disk_list 0 1 2 3
TO:
vg10_disk_list="${dsks[0]} ${dsks[1]} ${dsks[2]} ${dsks[3}"
Too many special characters for my scripting and pattern matching skills. I'm open to using another scripting language such as Perl if that suits the task better.
Let me know if you have any ideas. Currently, I just type in those array elements by hand. Otherwise the script is fully automated to capture and duplicate external disk configurations for any Unix server.
Thanks!
-john read
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2003 12:30 PM
02-24-2003 12:30 PM
Re: Advanced scripting challege
The correct challenge is to change the following:
FROM:
vg10_disk_list 0 1 2 3
TO:
vg10_disk_list="${dsks[0]} ${dsks[1]} ${dsks[2]} ${dsks[3]}"
thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2003 12:44 PM
02-24-2003 12:44 PM
SolutionYou can manipulate STR variable here and generate the output for as many variables as you need.
STR="vg10_disk_list 0 1 2 3"
VG=$(echo $STR|awk '{print $1}')
printf "$VG=\""
for I in $(echo $STR |sed 's/'$VG'//g')
do
printf "\$\{dsks\[$I\]\}"
done
printf "\"\n"
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2003 12:53 PM
02-24-2003 12:53 PM
Re: Advanced scripting challege
#/bin/ksh
COUNTER1=1
for DEV in `lvdisplay -v /dev/YOURVG/YOURLVOL|grep dsk|awk '{ print $2 }'|uniq`
do
DSK[$COUNTER1]=$DEV
(( COUNTER1 = "$COUNTER1" +"1" ))
done
This will pass the /dev/dsk/cXtXdX info to the subscripted variable DSK. The variable will count from 1 up instead of 0 up.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2003 07:21 AM
02-25-2003 07:21 AM
Re: Advanced scripting challege
Thanks! Here's how the final version ended up.
Source file:
#cat $vg_diskfile
vg07_disk_list 0 1 2 3 4 5 6 7 8 9 10 11 12 13
vg28_disk_list 14
vg11_disk_list 15 16 17 18
Script to make changes:
#!/bin/sh
vg_diskfile=/home/n721jjr/DR/vg_diskfile
LINES=`wc -l $vg_diskfile |awk '{print $1}'`
COUNT=1
while [[ $LINES -ge $COUNT ]]
do
STR=`sed -n ${COUNT}p $vg_diskfile`
VG=$(echo $STR|awk '{print $1}')
printf "$VG=\""
for I in $(echo $STR |sed 's/'$VG'//g')
do
printf "\$\{dsks\[$I\]\} "
done
printf "\"\n"
COUNT=$(($COUNT+1))
done
output:
vg07_disk_list="${dsks[0]} ${dsks[1]} ${dsks[2]} ${dsks[3]} ${dsks[4]} ${dsks[5]} ${dsks[6]} ${dsks[7]} ${dsks[8]} ${dsks[9]} ${dsks[10]} ${dsks[11]} ${dsks[12]} ${dsks[13]} "
vg28_disk_list="${dsks[14]} "
vg11_disk_list="${dsks[15]} ${dsks[16]} ${dsks[17]} ${dsks[18]} "
ps. I also liked the second response!
Thanks again.