- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: striping a file inside of a ksh 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
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
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
тАО08-19-2002 12:25 PM
тАО08-19-2002 12:25 PM
I am trying to write a ksh script here and could use some professional help (aside from the psychiatric stuff).
First the script i am writing is executing a command which produces an output file, what I would like to do with the output file is listed below:
1) Take the file and then utilize only the lines that contain the current date and the previous days date. Whatever is done with the other lines is ok since they are not needed.
2) Next I would like to take that output file and then wrap it in HTML code.
The script is listed here:
#!/usr/bin/ksh -v
#
# This script is being developed to provide a detailed report of the previous day's backup
# jobs from netbackup. This script will be executed daily at 10:00AM.
# Upon successful completion, the output from this script will be webified using html and then
# emailed to the it_backup_admins mailing list.
#
# This script must be executed utlizing the root user account.
# Environmental section
set -u
BASEDIR=/home/fgrosb01
DATE=`date +%Y%m%d`
SCRIPT_REVISION="HPUX-b.11.00.01"
SCRIPT_HPUX_VERSION=$(uname -r)
SCRIPT_SYSTEM=$(uname - n)
SCRIPT_USER=$(whoami)
SCRIPT_EXECUTION_TIME=$(date +'%Y/%m/%d/%H:%M:%S')
echo ${SCRIPT_SYSTEM} \(Version ${SCRIPT_REVISION}\) ${SCRIPT_EXECUTION_TIME}
echo _____________________________________________________________________
echo
if [ ${SCRIPT_USER} != "root" ] ; then
echo
echo "This program must be executed utilizing the root logon id only"
echo
return 501
fi
echo _______________________________________________________________________
###########################################################################
#
# This section of the script will execute the bpdbjobs command utilizing
# the file /home/fgrosb01/.xbpmonrcfg as it's configuration file for the
# output.
bpdbjobs -header -report -format $BASEDIR/.xbpmonrcfg > /home/fgrosb01/$DATE.bpdbjobs.output
I am attaching a copy of the output file as well.
Thank you in advance. Points will be awarded.
fg.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-19-2002 12:50 PM
тАО08-19-2002 12:50 PM
Re: striping a file inside of a ksh script
Do the same for yesterdays date.
Then 'grep' for those dates in the output file and put it into a tmp file.
Grep for todays date.
grep $TODAYSDATE inputfile > /tmp/outputfile
grep $YESTERDAYSDATE inputfile >> /tmp/outputfile
Sort the file if needed. man sort.
Then cat the html header into a file, concat backup output, and concat html footer into file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-19-2002 04:06 PM
тАО08-19-2002 04:06 PM
Re: striping a file inside of a ksh script
cat inputfile | grep -e "08/17/2002" -e "08/18/2002" | awk '{printf("
\n%s\n",$0);}'
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-19-2002 06:25 PM
тАО08-19-2002 06:25 PM
SolutionThe issue is getting yesterday's date.
I will keep a stamp file to get yesterday's date. Or you can use Clay's Caljd.sh script (search in the forums) to determine the date of yesterday.
To use my method, you will first need to touch a file yesterday.stamp with current yesterday's date in it. I will just modify your script a little bit.
BASEDIR=/home/fgrosb01
STAMP=$BASEDIR/yesterday.stamp
RESULT=$BASEDIR/result
DATE=`date +%Y%m%d`
Y_DATE=`cat $STAMP`
SCRIPT_REVISION="HPUX-b.11.00.01"
SCRIPT_HPUX_VERSION=$(uname -r)
SCRIPT_SYSTEM=$(uname - n)
SCRIPT_USER=$(whoami)
SCRIPT_EXECUTION_TIME=$(date +'%Y/%m/%d/%H:%M:%S')
echo ${SCRIPT_SYSTEM} \(Version ${SCRIPT_REVISION}\) ${SCRIPT_EXECUTION_TIME}
echo _____________________________________________________________________
echo
if [ ${SCRIPT_USER} != "root" ] ; then
echo
echo "This program must be executed utilizing the root logon id only"
echo
return 501
else
grep $Y_DATE $OUTPUT > ${RESULT}.${DATE}
cat << EOF > ${RESULT}.${DATE}.html
EOF
cat ${RESULT}.${DATE} >> ${RESULT}.${DATE}.html
cat << EOF >> ${RESULT}.${DATE}.html
fi
echo $DATE > $STAMP
echo _______________________________________________________________________
###########################################################################
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-19-2002 06:27 PM
тАО08-19-2002 06:27 PM
Re: striping a file inside of a ksh script
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2002 02:47 AM
тАО08-20-2002 02:47 AM
Re: striping a file inside of a ksh script
I have also been trying to give thought to striping out certain fields to create another file, kind of seperating some columns from the main output, can any of you provide me with an idea on how that would be done.
Ex: take the jobid, jobstatus, start time, end time and make a new file with those fields.
I appreciate the help on this.
fg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2002 03:32 AM
тАО08-20-2002 03:32 AM
Re: striping a file inside of a ksh script
cat /tmp/inputfile | awk '{
jobid=substr($0,1,10);
jobtype=substr($0,14,11);
jobstate=substr($0,23,8);
jobstatus=substr($0,31,9);
jobclass=substr($0,40,28);
jobschedule=substr($0,70,19);
jobclient=substr($0,89,26);
jobserver=substr($0,116,26);
jobstarted=substr($0,143,19);
jobelapsed=substr($0,169,14);
jobended=substr($0,180,19)
jobKbytes=substr($0,199,14);
jobfiles=substr($0,213,14);
jobestimated=substr($0,227,7);
printf("%s_%s_%s_%s_%s_%s_%s_%s_%s_%s_\n",jobid,jobtype,jobschedule,jobclient,jo
bserver,jobstarted,jobended,jobKbytes,jobfiles,jobestimated);
}'
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2002 05:00 AM
тАО08-20-2002 05:00 AM
Re: striping a file inside of a ksh script
That looks interesting, can you explain to me what that is actually doing since i am not too proficient with awk.
TY.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2002 05:28 AM
тАО08-20-2002 05:28 AM
Re: striping a file inside of a ksh script
the script is cat'ing the file to awk. "awk", when it receives data from a pipe (see the cat to awk below), it places each separate line in variable $0 (dollar-sign zero), much like the shell's do.
#!/usr/bin/ksh
cat /tmp/inputfile | awk '{
# and here we are "parsing" the fields
# based upon their position within
# the file:
jobid=substr($0,1,10);
#
# the job ID (above) starts in position 1 and is 10 characters long
#
jobtype=substr($0,14,11);
#
# the job type (above) starts in column 14 and is 11 charcaters long
#
# the $0 is the whole line
jobstate=substr($0,23,8);
jobstatus=substr($0,31,9);
jobclass=substr($0,40,28);
jobschedule=substr($0,70,19);
jobclient=substr($0,89,26);
jobserver=substr($0,116,26);
jobstarted=substr($0,143,19);
jobelapsed=substr($0,169,14);
jobended=substr($0,180,19)
jobKbytes=substr($0,199,14);
jobfiles=substr($0,213,14);
jobestimated=substr($0,227,7);
#
# here I am just outputing some variables with an
# underscore (_) just to make sure I have the fields
# aligned.
#
printf("%s_%s_%s_%s_%s_%s_%s_%s_%s_%s_\n", jobid, jobtype, jobschedule, jobclient, jobserver, jobstarted, jobended, jobKbytes, jobfiles, jobestimated);
}'
The %s in the print statement is a string identifier.
Just take the fields you want, and put them into a print statemnet like the one above. Make sure you have an %s (percent ess) for each field being outputed.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2002 05:32 AM
тАО08-20-2002 05:32 AM
Re: striping a file inside of a ksh script
Your AWESOME. Thank you very much for that piece. It's an awesome idea.
FG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2002 05:38 AM
тАО08-20-2002 05:38 AM
Re: striping a file inside of a ksh script
Of course the same can be done in perl, and almost exactly as it's done in awk.
live free or die
harry