-
Can somebody help this shell programming question? Thank you!
I need to test if any trace file (.trc) was created in a directory. The following code block is just a try. I think the "*" is not working in the case. How to correct the syntax?
if
[[ -f "/u01/app/oracle/admin/test/udump/*.trc" ]]
then
echo "found!"
else
echo "not found!"
fi
-
Yes, you explicitly looking for a file named "*.trc", which you probably don't have. I would use find instead:
Code:
find /u01/app/oracle/admin/test/udump -name \*.trc -ls
You can also combine with other commands, such as rm to remove files older than 10 days:
Code:
find /u01/app/oracle/admin/test/udump -name \*.trc -type f -mtime +10 -print -exec rm -f {} \;
man find gives you all the options...
-
Your reply is excellent. However, I need to include this code block in a shell program and run it on cron job and notify me whenever there is a trace file being created.
"find" is more likely to be used in an interactive session. Right?
So, "if" condition is the command that I need to use. How to correct the syntax so that I can use the "*" wild card?
-
you can perfectly use find in a shell script, like any other non-interactive UNIX command, else use :
if [ -f /u01/app/oracle/admin/test/udump/*.trc ]
-
Use the find command in SHELL script and store the out put in one variable, and the variable out put to take necessary action in the If condition
In this case you can use the power of FIND command and achieve what you want.