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 here.

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-25-2005
Registered User
 

Join Date: Feb 2005
Posts: 137
Stumble this Post!
Help!!

Hi Folks, I have a bit of a problem...

I have a directory with 300+ report files in it.
I need to make a script that will take all these file names and run them within a command.
This is the command i run to produce the report i need:

twprint -m r -r /usr/local/tripwire/tfs/report/x21nwh51-20051009-060024.twr -o /export/home/bgalante/ax21nwh51-1009.html -F html

the x21nwh51-20051009-060024.twr is the report file.

Any help please? I know i prolly need to do a foreach loop, but i suck big at scripting so your help will be greatly appreciated.
Thanks!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-25-2005
Registered User
 

Join Date: Oct 2005
Posts: 22
Stumble this Post!
#!/bin/sh

# declare variables
RPTDIR="/usr/local/tripwire/tfs/report/"
RPTS=`ls -1 $RPTDIR/*.twr`
RPTOUT="/export/home/bgalante"

# for every report in your report listing array
for rpt in $RPTS
do
# strip first part of the name
# for example x21nwh51-20051009-060024.twr
# would be x21nwh51
rpthtml=`echo $rpt | cut -d- -f1`
# create html from report and make the name unique
# x21nwh51-20051025-15:11:58.html
twprint -m r -r $RPTDIR/$rpt -o $RPTOUT/$rpthtml-`date +%Y%m%d-%H:%M:%S`.html -F html
done
Reply With Quote
  #3 (permalink)  
Old 10-25-2005
Registered User
 

Join Date: Feb 2005
Posts: 137
Stumble this Post!
here is what im getting now...

Error: File cannot be opened.
### Filename:
### /usr/local/tripwire/tfs/report///usr/local/tripwire/tfs/report//x21nwh51-20041029-132911.twr
### No such file or directory
### Exiting...


Thanks for helping, im trying to figure this one out, do you know why im getting that error?
Reply With Quote
  #4 (permalink)  
Old 10-25-2005
Registered User
 

Join Date: Oct 2005
Posts: 22
Stumble this Post!
Fixed a line...see below

#!/bin/sh

# declare variables
RPTDIR="/usr/local/tripwire/tfs/report"
# Incorrect syntax to get basename of file
# this has been corrected
RPTS=`cd $RPTDIR && ls -1 *.twr`
RPTOUT="/export/home/bgalante"

# for every report in your report listing array
for rpt in $RPTS
do
# strip first part of the name
# for example x21nwh51-20051009-060024.twr
# would be x21nwh51
rpthtml=`echo $rpt | cut -d- -f1`
# create html from report and make the name unique
# x21nwh51-20051025-15:11:58.html
twprint -m r -r $RPTDIR/$rpt -o $RPTOUT/$rpthtml-`date +%Y%m%d-%H:%M:%S`.html -F html
done

Last edited by supaphat; 10-25-2005 at 10:20 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0