Shell programming - running the exe file and printing the output.. ?

hai

i have a directory lib

in that lib directory i have 10 batch files.

step i have to do is 1) EXECUTE ALL THE FILES by using the command dwarfdump <filename>| grep DW_AT_SUN_command_line

and put the output in one text file.instead of executing the files for all the 10 files .. can i read the files in the directory lib and pass the file name and print the filename and finally the output in the text file..?

how can i do it?

Kindly help .. i am very new to unix..

S

Is this homework? If not,
show us what have you tried so far.

Welcome to forums by the way :slight_smile:

You can tell me

1) how to read all the files in a directory

and i can put that filename into a variable and execute the command >> output.file

Help

S

try this, not efficient though

ls directory_name | while read filename
do
echo $filename
done

ls ./logfile/lib | while read filename
do
echo $filename
dwarfdump $filename | grep DW_AT_SUN_command_line >> dward_output.txt
done

this is giving the output in dwarf_output.txt

but it is better if we have filename at the beginning of outputfile txt. before command execution.

just change this

echo $filename

to

echo $filename >> outputfilename.txt

thanks madhan..

S

when i execute the shell script file dwarf_output.ksh as

ls  /logfile/lib  | while read filename
do
echo "STARTING THE FILE" $filename >>dwarf_output.txt
echo "*************************************">>dwarf_output.txt
dwarfdump $filename | grep DW_AT_SUN_command_line >>dwarf_output.txt
echo "END OF FILE " $filename >>dwarf_output.txt
done

the output file dwarf_output.txt contains dwarf_output.ksh also. telling

STARTING THE FILE dwarf_output.ksh
*************************************
END OF FILE  dwarf_output.ksh

i want to elimate the files starting with .ksh and .sql files.. how can i do this...?

kindly help
S

I guess those are verbose messages.
In that case,

echo "verbose" > /dev/tty
echo "log message" > to_some_log_file

it it not verbose

dwarf_output.ksh is the file where actual shell script is written. so when i execute

ls /logfile/lib | while read filename
do
echo "STARTING THE FILE" $filename >>dwarf_output.txt
echo "*************************************">>dwarf_output.txt
dwarfdump $filename | grep DW_AT_SUN_command_line >>dwarf_output.txt
echo "END OF FILE " $filename >>dwarf_output.txt
done

the scripts execute it's own file. ie

dwarfdump dwarf_output.ksh | grep DW_AT_SUN_command_line 

so i dont want .ksh file to execute. how to elimate .ksh and .sql files

S

First, its not a good idea to have bin files (scripts, executable, ..) in the same directory as in directory where data files are available.

Both of them should be abstracted in different directories.

Second,
probably you could check for existence of the literals, '.ksh' or '.sql' in the filename before processing them,

if required string literals are there 
then
  continue with the next file processing 
else 
  proceed with actual processing
fi

hai

i have idea about filtering the files with find ./ -name "*.ksh" -print
but what is the command for listing all the files without .ksh and .sql files..?

can u pls tell the unix command for this..

waiting

S

Try this:

find . -type f ! \( -name "*.txt" \) ! \( -name "*.sql" \) 

Your version of find could differ from mine, if you get errors refer your local find command man page for more information.

if you are want your script not to execute itself, try

 
ls /logfile/lib | while read filename
do
if [ ! -f dwarf_output.ksh ]; then
echo "STARTING THE FILE" $filename >>dwarf_output.txt
echo "*************************************">>dwarf_output.txt
dwarfdump $filename | grep DW_AT_SUN_command_line >>dwarf_output.txt
echo "END OF FILE " $filename >>dwarf_output.txt
fi
done

or

 
ls /logfile/lib | while read filename
do
if [ ! -f $0 ]; then
echo "STARTING THE FILE" $filename >>dwarf_output.txt
echo "*************************************">>dwarf_output.txt
dwarfdump $filename | grep DW_AT_SUN_command_line >>dwarf_output.txt
echo "END OF FILE " $filename >>dwarf_output.txt
fi
done