New to Shell scripting: Can you check it?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New to Shell scripting: Can you check it?
# 1  
Old 10-27-2008
New to Shell scripting: Can you check it?

I am trying to write a script to get all the html files under a source directory and and for each html file, run a program with html file as an argument. This program generates an output which I need to save as htmlfilename.txt ( right now i was trying to print it on the command line)

SOURCE_DIR=/a/b/c

#location of program
EXE_DIR=/d/f/g

for htmlfile in 'find $SOURCE_DIR \( -name *.html \)';
do
output=$($EXE_DIR/program "$htmlfile");
echo $output;
echo "Printing the expected output" ;
done

What am I doing wrong? I am not getting any output.
Also How do you assign the output of a command to a variable?
And how do you redirect the output to a file with a specific name?

Thanks much in advance!
# 2  
Old 10-27-2008
For a start
Quote:
\( -name *.html \)
Will not produce the result you expect...
use either \*.html or "*.html"
# 3  
Old 10-27-2008
Using of find is unnecessary, to select the html files you can do something like:

Code:
SOURCE_DIR=/a/b/c

#location of program
EXE_DIR=/d/f/g 

for htmlfile in "$SOURCE_DIR"/*.html
do
  output=$("$EXE_DIR"/program "$htmlfile")
  echo "$output"
done

Regards
# 4  
Old 10-27-2008
Thanks Franklin52 and Vbe for the reply.

I was trying to use 'Find' as my My SOURCE_DIR have mulitple directories and which in turn have html and other files. For example:
SOURCE_DIR= /a/b/c
-c has subdirectories h , d, f and g
-subdirectories h and d has few html files
-f and g has more subdirectories and the subdirectories might have html files

----
for htmlfile in "$SOURCE_DIR"/*.html
----
This works only if SOURCE_DIR have html file.

Can you check whats' wrong with my find command?

Thx so much!
# 5  
Old 10-27-2008
Replace this line:

Code:
for htmlfile in "$SOURCE_DIR"/*.html

with:

Code:
for htmlfile in $(find $SOURCE_DIR -name "*.html")

Regards
# 6  
Old 10-27-2008
Aha, Got the common sense of shell scripting nowSmilie I was trying to do

Code:
for htmlfile in 'find $SOURCE_DIR -name *.html '

So the idea is to get the result return by 'find' in a variable.

Code:
for htmlfile in $(find $SOURCE_DIR -name "*.html")

Thanks guys! its really helpful . Now next target is to put all output into txt files with the same name as html files.

output = program "a/b/d/f/123.html"
redirect output to a/b/d/f/123.txt
# 7  
Old 10-28-2008
ok I think I need help here.
I need to redirect the output to a file with the same name and location as html file

for htmlfile in "$SOURCE_DIR"/*.html
do
$($EXE_DIR"/program "$htmlfile") >> output file
## where putput file = htmlfile.txt""
echo "$output"
doneWhat should I use to create the name of the output file similar to html file?
Can I use sed to copy the location and name of .html file and create a new .txt file with the same name and at the same location?

For example:
output=program "a/b/d/f/123.html"
redirect output to a/b/d/f/123.txt

thx!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check if the JAVA Program is successfully executed in sh shell scripting

Hi , I have written a shell script to call a java program say load_id.sh .This sh script indeed is executed implicitly in other sh script which calls 2 more sh scripts one by one. I need to check if the load_id.sh (which calls java program) is executed successfully only then continue with... (1 Reply)
Discussion started by: preema
1 Replies

2. Shell Programming and Scripting

How to check the datatypes of the columns are same through shell scripting?

Hi, We have a requirement like, to check the datatypes of columns against database. After loading the sample data in to one of the database, need to compare the datatypes of the columns are matching with the provided files. Is there a way that we can achieve through shell scripting. We... (7 Replies)
Discussion started by: Samah
7 Replies

3. AIX

Need help in scripting to check if rootvg is mirrored or not

Hi Can some one help me with a script which when executed will check and tell if all the LV's in rootvg are mirrored or not. Say for example in the below server we could see that everything is mirrored except dumplv2. So if I execute the script it should tell that all are mirrored except... (7 Replies)
Discussion started by: newtoaixos
7 Replies

4. Shell Programming and Scripting

C shell scripting, check if link exists on remote servers

Hi, I'm new to C Shell programming. I'm trying to check if a sym link exists on remote server if not send email. I'm not having much luck. Can anyone help? Here is what I have written but it doesn't work. It tells me that my variable was not defined. Here is part of the script, the second... (0 Replies)
Discussion started by: CDi
0 Replies

5. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. UNIX for Dummies Questions & Answers

SQL Connection check though Scripting

Hi Guys, I wanted to check the sql connection through scripting if it is avilable then proceed else stop the process I was trying sqlplus -L username/passwd@sid if this is not sucess it gives non-zero. but if it is success it is going into the sqlplus prompt. So how could i get out... (2 Replies)
Discussion started by: Swapna173
2 Replies

8. Solaris

How to check the file existence using shell scripting in Solaris-10

Hi, I have a script which will check the fiel existence, the lines are as below if !(test -d ./data) then mkdir data fi In the first line error occurs as below generatelicense.sh: syntax error at line 2: `!' unexpected Where as this script works fine in linux OS. How to solve... (2 Replies)
Discussion started by: krevathi1912
2 Replies

9. UNIX for Dummies Questions & Answers

How to check process/cpu utilisation thru unix shell scripting

Dear Champs, Can anybody help me out to write a shell script , which will check whether the process is running , if running then divide the process into 2 so that next var it can take process parallel . Let ps -ef | grep a.sh => shows running note a.sh will take a process of next... (0 Replies)
Discussion started by: manas_ranjan
0 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question