- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 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
Discussions
Discussions
Forums
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
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
тАО01-19-2007 01:41 AM
тАО01-19-2007 01:41 AM
I have a tarball of files per machine for about 1500 machines. I need a script to read each tarball and extract certain info from files within the tarball. I need this info to be put in a comma separated flat file so it can be read in to Excel.
so far I have
cd /export/home/Explorers
ls *.gz | while read FILE
do
cd /export/home/Explorers
# copy file to temp area
cp $FILE ./temporary
cd temporary
# extract the files
gunzip $FILE
tar xf *.tar
cd explorer.*
#extract the info
grep Hostname README
grep Hostid README
grep Release README
grep Company README
grep Kernel README
grep architecture README
grep Date README
grep Uptime README
#more info to be added
#clean up - remove contents of temp before next explorer
cd ..
rm -r /export/home/SUN/Explorers/temporary/*
done
The grep statements bring out the lines I require, but for each grep I need the data after the colon to be added to a csv file, and a new line to be started for each separate tar ball.
example output of the greps:
Hostname: ipcsoiwa
Hostid: 8075ac8c
Release: 5.6
Kernel architecture: sun4d
Kernel version: SunOS 5.6 Generic 105181-06
Kernel architecture: sun4d
Application architecture: sparc
Date: 2005.05.30.04.54
Uptime: 6:02am up 43 min(s), 2 users, load average: 1.34, 1.16, 0.66
Thanks
Mark
Solved! Go to Solution.
- Tags:
- csv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2007 01:57 AM
тАО01-19-2007 01:57 AM
SolutionHOST=$(grep Hostname README | awk -F : '{ print $2}')
HOSTID=$(grep Hostid README | awk -F : '{ print $2}')
RELEASE=$(grep Release README | awk -F : '{ print $2}')
COMPANY=$(grep Company README | awk -F : '{ print $2}')
KERNEL=$(grep Kernel README | awk -F : '{ print $2}')
ARCH=$(grep architecture README | awk -F : '{ print $2}')
DATE=$(grep Date README | awk -F : '{ print $2}')
UPTIME=$(grep Uptime README | awk -F : '{ print $2}')
echo "${HOSTNAME},${HOSTID},${RELEASE},${KERNEL},${ARCH},${DATE},${UPTIME}" >> /dir/afile
Another slight improvement is you can combine your gunzip and tar commands into a single line.
Instead of:
gunzip $FILE
tar xf *.tar
Try this:
gzcat $FILE | tar xf -
(Note there is a space between the 'xf' and the '-')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2007 02:01 AM
тАО01-19-2007 02:01 AM
Re: shell script
You have this grep statement:
grep Kernel README
which will return 2 lines of data:
Kernel architecture: sun4d
Kernel version: SunOS 5.6 Generic 105181-06
Then you also grep for architecture. Which will return the Kernel architecture line again. For those you should probably do this:
KERNEL=$(grep "Kernel version" README | awk -F : '{ print $2}')
ARCH=$(grep "Kernel architecture" README | awk -F : '{ print $2}')
This way you should only get one line per grep.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2007 02:15 AM
тАО01-19-2007 02:15 AM
Re: shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2007 03:46 AM
тАО01-19-2007 03:46 AM
Re: shell script
it's time for awk, IMHO. I see no info for 'Company', so I do not anchor that string and assume the requested value is the last field (like for the other pattern).
awk '/^Hostname:/ {hname=$NF}
/^Hostid:/ {hid=$NF}
/^Release/ {rel=$NF}
/Company/ {com=$NF}
/^Kernel architecture:/ {arch=$NF}
/^Kernel version:/ {ver=$3;for(i=4;i<=NF;i++) ver=ver" "$i }
/^Application architecture:/ {mach=$NF}
/^Date:/ {date=$NF}
/^Uptime:/ {upt=$2;for(i=3;i<=NF;i++) upt=upt" "$i }
END { printf("%s;%s;%s;%s;%s;%s;%s;%s;%s\n",hname,hid,rel,com,arch,ver,mach,date,upt)}' README
I would add some error checking as well, like instead
>>
gunzip $FILE
tar xf *.tar
cd explorer.*
<<
use in KSH
if ! gunzip<$file | tar xf -
then exit 1
fi
cd explorer.*
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2008 04:17 PM
тАО12-10-2008 04:17 PM