2004/09/03: Wilfredo Duarte asks:
I have the following script that will be used inside the Oracle OEM console for monitoring the detection of the counting of kind of file in the filesystem. (oratclsh)
What I want to detect is if there are files with the extension *.Z in the directory
if {[file exists "/cognos_data/ORADATA/arc/*.Z"] } {
puts YES
puts -1
} else {
puts NO
puts 2
}
When in the OS I issue the oratclsh command and then issue the above Solaris script, it gave me the result of NO, when indeed the directory is filled up with files like this:
arch_mapdev0000006291.arc.Z arch_mapdev0000006471.arc.Z
arch_mapdev0000006292.arc.Z arch_mapdev0000006472.arc.Z
arch_mapdev0000006293.arc.Z arch_mapdev0000006473.arc.Z
arch_mapdev0000006294.arc.Z
When I change the script to the following, it gave me the error "child process exited abnormally:"
oratclsh[20]- if {[ls cognos_data/ORADATA/arc/*.Z | wc -l > 1] } {
puts YES
puts -1
} else {
puts NO
puts 2
}
child process exited abnormally
oratclsh[21]-
Also the same result if I change the first line to this:
if {[ls cognos_data/ORADATA/arc/*.Z | wc -l > 1;] } {
I need help with this
'''Answer ([sm])'''
Your initial attempt was close. The problem is, [file exists] doesn't do wildcard expansion, so it's looking for a file named *.Z. The command you want to use is [glob]. glob returns an error if no files match the given pattern, so you'll either need to wrap your glob call in a [catch] statement, or else pass glob the -nocomplain flag and check for a non-empty list. Here's examples of the two options:
if {[llength [glob -nocomplain "/cognos_data/ORADATA/arc/*.Z"]] > 0 } {
puts YES
puts -1
} else {
puts NO
puts 2
}
or,
if {[catch {glob "/cognos_data/ORADATA/arc/*.Z"}] == 0} {
puts YES
puts -1
} else {
puts NO
puts 2
}
-----
CategoryDatabases