DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: shell programming question

  1. #1
    Join Date
    Mar 2001
    Posts
    287
    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


  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    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...
    Jeff Hunter

  3. #3
    Join Date
    Mar 2001
    Posts
    287
    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?


  4. #4
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    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 ]

  5. #5
    Join Date
    Mar 2000
    Location
    CA
    Posts
    317
    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.
    Thanks
    Kishore Kumar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width