- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- A Powerful shell 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
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
10-31-2001 01:50 PM
10-31-2001 01:50 PM
A Powerful shell script!
I have a file of the format below :
......
......
and so on
------------------------------------------------------
IBE augmentation level
IBE rule
1527753849 1163 Exports/CC
1527753849 1163 Exports/Global_wrapper
1527753849 1163 Exports/yacc
4294967295 0 FILELIST.IBE
3618088840 5846 README.FIRST
ABE.IC augmentation level
clear rule
1743432609 16384 usr/bin/clear
dev rule
68954040 218620 dev/core
dld rule
1105456478 102400 usr/lib/dld.sl
-----------------------------------------------------------
Each level corresponds to a source directory
eg.IBE corresponds to /ha/be/sa_ems/IBE/
and the locations correspond to files under them.
eg if there is Exports/CC, it means
there is a file /ha/be/sa_ems/IBE/Exports/CC
and it has corresponding checksum,size as indicated
What I need to do:
copy the files to a particular directory from all these various locations
eg.Let's say the target root dir is /BE/
the for the line
Exports/CC
I will have to
1. find the level and get the base source dir
In this case it is IBE which corresponds to /ha/be/sa_ems/IBE/
2.create any sub-dirs under /BE if required.
In this case it is Exports
So, I will have to create Exports under /BE/
3.check for the file and verify whether the checksum and sixe are correct
4.If step 3 succeeds,copy it to the target dir
In this case it is CC
so,I will have to copy CC to /BE/Exports/CC
5.Retain the permissions,owner,group of the file.
It is really big process,and there are hundreds of such lines and there are many such files.
Can anyone provide some script or any ideas/suggestions
/or any information on these.
It would be highly appreciated and highly Rewarded:)
Waiting for many responses:)
-Jayes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2001 03:04 PM
10-31-2001 03:04 PM
Re: A Powerful shell script!
Good food. Try this.
//start
#!/usr/bin/ksh
#change these to the applicable
INFILE=/full_path_to_your_formatted_file
TMP=/tmp/input$$
PARENT=/ha/be/sa_ems
TARGET=/
#Change if you want
LOG=/tmp/output.log
ERRLOG=/tmp/err.log
TMPTAR=/tmp/tmp.tar
for SRC in `grep "augmentation level" $INFILE |awk '{print $1}'`
do
cd ${PARENT}/${SRC}
mkdir ${TARGET}/${SRC}
sed -n '/'$SRC' augmentation level/,/augmentation level/p' $INFILE \
|sed '/augmentation level/d' |sed '/rule/d' > $TMP
cat $TMP|while read LINE
do
FILE=`echo $LINE|awk '{print $3}'`
if [ -f $FILE ]
then
RESULT=`cksum $FILE`
if [ "$RESULT" = "$LINE" ]
then
tar cf $TMPTAR $FILE
cd ${TARGET}/${SRC}
tar xf $TMPTAR
echo "$SRC: $LINE has been successful" >> $LOG
cd ${PARENT}/${SRC}
else
echo "$SRC: $LINE has checksum problems" >> $ERRLOG
fi
else
echo "$SRC: $LINE doesnot exist" >> $ERRLOG
fi
done
done
rm $TMP $TMPTAR
//END
See if it works... I am just tarring it up and untarring so that it will take care of permissions/ownership and subdirectories etc.,
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2001 03:36 PM
10-31-2001 03:36 PM
Re: A Powerful shell script!
You can copy & paste this script and can have it working.
Response is very important so that we will know our mistakes.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2001 03:53 PM
10-31-2001 03:53 PM
Re: A Powerful shell script!
There is only one small problem (rather I should have not taken note of it while assigning points)
mkdir should have been mkdir -p.
The other point is : the PARENT is dependent on the augmentation level.Well,My mistake,I did not give full info.
The last line may or may not be augmentation level line.
Sridhar,Your help is really appreciated.
-Jayesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2001 08:07 PM
10-31-2001 08:07 PM
Re: A Powerful shell script!
You are right.. It should be mkdir -p.
The second thing is that the some portion of your PARENT DIRECTORY is independent of your augmentation level. So, we can just assign it to $PARENT as it doesnt' change.
If you check the other line, I am going into the dependent directory by doing a
cd ${PARENT}/${SRC} where SRC is derived based on each "augmentation level" header.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2001 02:31 AM
11-01-2001 02:31 AM
Re: A Powerful shell script!
Here's how to do it within awk. Pls note, I've put echo statements in to show what it *would* do. Remove the "echo" to actually run the script.
===========================================
#!/bin/sh
INDIR=/ha/be/sa_ems
OUTDIR=/BE
INPUT=your_input_file_name
awk '
/augmentation level/{SUBDIR=$1;next}
NF==3{
FNAME=$3;$3=INDIR"/"SUBDIR"/"$3;line=$0;FILE=$3;$0="";print FILE
"cksum "FILE " 2>/dev/null"|getline;close "cksum "FILE "2>/dev/null"
print line
if (line == $0)
{
"dirname "FNAME|getline;close "dirname "FNAME
system ("echo mkdir -p "OUTDIR"/"$0)
system("echo cp -p "INDIR"/"SUBDIR"/"FNAME" "OUTDIR"/"FNAME)
}
}' INDIR=$INDIR OUTDIR=$OUTDIR $INPUT
============================================
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 01:10 AM
11-03-2001 01:10 AM
Re: A Powerful shell script!
What could be the reason?
-----------------------------
cat $TMP|while read LINE
do
FILE=`echo $LINE|awk '{print $3}'`
if [ -f $FILE ]
then
RESULT=`cksum $FILE`
if [ "$RESULT" = "$LINE" ]
then
.....
-----------------------------