The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 04:06 AM
Shell script to append a time for the existing error log file gsprasanna UNIX for Advanced & Expert Users 12 07-12-2007 06:07 AM
sql query results in unix shell script skyineyes UNIX for Dummies Questions & Answers 1 06-20-2007 11:56 AM
How to insert new line in the data file using the script Sona UNIX for Dummies Questions & Answers 2 08-22-2006 02:17 AM
How to input username on text file into finger command on shell script Micz Shell Programming and Scripting 3 11-08-2005 02:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-11-2005
littlejon littlejon is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 4
script to run shell command and insert results to existing xml file

Hi. Thanks for any help with this. I'm not new to programming but I am new to shell programming. I need a script that will

1. execute 'df -k' and return the volume names with specific text
2. surround each line of the above results in opening and closing xml tags
3. insert the results of step #2 into an existing file after a specific opening xml tag.

Any help would be greatly appreciated!

littlejon
  #2 (permalink)  
Old 08-11-2005
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
I have this old script ksh script which takes the output from df and produces a html page. It is specific to HP-UX (hence the "df -Pkl") but you could adapt it to your needs. You probably don't need the bar graph showing disk capacity!
Code:
#!/usr/bin/ksh
exec 3> df.html
print -u3 '<HTML><HEAD><TITLE>STATS</TITLE></HEAD><BODY>'
print -u3 '<H3>'$(uname -n)'</H3><TABLE BORDER=2 CELLSPACING=0 CELLPADDING=2>'
print -u3 '<TR><TH>Filesystem</TH><TH>1024-blocks</TH><TH>Used</TH>'
print -u3 '<TH>Available</TH><TH>Capacity</TH><TH>Mounted On</TH></TR>'
df -Pkl |awk 'NR>1 && NF==6'|sort|while read FS SIZE USED FREE PERC MOUNT
do
  print -u3 '<TR><TD>'$FS'</TD><TD ALIGN=RIGHT>'$SIZE'</TD>'
  print -u3 '<TD ALIGN=RIGHT>'$USED'</TD><TD ALIGN=RIGHT>'$FREE'</TD>'
  print -u3 '<TD><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0><TR>'
  print -u3 '<TD WIDTH='$((150*$USED/$SIZE))' BGCOLOR="black"></TD>'
  print -u3 '<TD WIDTH='$((150*$FREE/$SIZE))' BGCOLOR="gray"></TD>'
  print -u3 '<TD><FONT SIZE=-1 COLOR=black> '$PERC'</FONT></TD>'
  print -u3 '<TR></TABLE></TD><TD>'$MOUNT'</TD></TR>'
done
print -u3 '</TABLE><P>Generated at '$(date '+%H:%M on %d-%b-%y')'</BODY></HTML>'
exec 3<&-

  #3 (permalink)  
Old 08-12-2005
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
You can try something like that :

Code:
result_file=df.dat

open_tag='<TAG>'
close_tag='</TAG>'
insert_point='<XML>'

df_file=/tmp/$$.tmp
temp_file=/tmp/$$.tmp

# Build lines to be inserted in result file
df -k | tail +2 | while read line
do
   echo "${open_tag}\n${line}\n${close_tag}"
done >> ${df_file}

# Insert lines in result file
sed -e "/${insert_point}/r ${df_file}" ${result_file} > ${temp_file}
mv ${temp_file} ${result_file}


Jean-Pierre.
Bits Awarded / Charged to aigles for this Post
Date User Comment Amount
07-18-2009 littlejon N/A 500
  #4 (permalink)  
Old 08-12-2005
littlejon littlejon is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 4
Thanks to both Ygor and Aigles. I went with Aigles' suggestion and it worked like a charm. Of course, I tweaked it to meet my needs. I was originally trying to use standard programming techniques to solve this problem. I am now officialy amazed at the power of sed and shell programming. Thank you, again! And, thanks to unix.com for the forum!
  #5 (permalink)  
Old 08-12-2005
littlejon littlejon is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 4
Thanks, jerardfjay. Your post must have just made it while I was typing my last one. I think I've got the problem solved. I appreciate your suggestion, though. littlejon.
  #6 (permalink)  
Old 08-12-2005
jerardfjay jerardfjay is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 146
Quote:
Originally Posted by Ygor
I have this old script ksh script which takes the output from df and produces a html page. It is specific to HP-UX (hence the "df -Pkl") but you could adapt it to your needs.
I may be old, but works nicely. Jerardfjay
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0