jalge2,
I'm not sure that this script will do what you expect.
echo "\tPlease enter the battery number you wish to search f
or..."
+4 read ans
+5
+6 if [[ $ans != 0 ]]
+7
+8 then
+9 cat /dso/eis/log/batlog.log.* |grep $ans
+10 fi
if $ans = 0, then the next line executed is:-
echo "\tWould you like to print this? (y/n)"
is this what you want?
cat /dso/eis/log/batlog.log.* |grep $ans
will find all partial or complete matches.
ie is $ans = 20, then 200 and 120 will match.
You need to use grep -w to match a word, or change the pattern to " ${ans} ", depending upon which characters surround the battery number in the file. Some grep don't have -w switch.
What if the battery number is not found in ANY log file? You script assumes that it is.
Will the battery number only exist in 1 file?
The following command will put all filenames that contain $ans in $Files
(NB you don't need cat to do this)
Files=$(grep -lw ${ans} /dso/eis/log/batlog.log*) 2> /dev/null)
If there is more that 1 file, you need to process them thusly:-
for File in $Files
do
...
done
when you need to check a variable for case, typeset the variable to either upper or lower, and do a simple test.
typeset -u ans1
and then simply [[ $ans1 = Y ]] .....
So, the script would look something like this:-
# /bin/ksh!
typeset -u ans1
read -- ans?"Please enter the battery number you wish to search for "
[[ -z $ans || $ans = 0 ]] && #ksh compound if syntax
{
print "No battery number entered. Exiting.."
exit 1
}
Files=$(grep -lw ${ans} /dso/eis/log/batlog.log.* 2> /dev/null) ||
{
print "Can't find battery number $ans in any log file. exiting.."
exit 1
}
for File in $Files
do
print "Battery # $ans found in file $File"
print "First line of that file is:-\n"
head -1 $File
read -- ans1?"Would you like to print this? (y/n)"
[[ $ans1 = Y ]] &&
lp -dpcl@pr7 $File
done
exit 0