Find out why a program can't seem to access to a file

2010-05-05 278 words 2 mins read

$ strace php tias.php -e open,access 2>&1 | <a class="zem_slink freebase/en/grep" href="http://en.wikipedia.org/wiki/Grep" title="Grep" rel="wikipedia">grep foo.txt Sometimes a program refuses to read a file and you&#8217;re not sure why. You may have display_errors turned off for <a class="zem_slink freebase/en/php" href="http://www.php.net/" title="PHP" rel="homepage">PHP or something. In this example, fopen(&#8217;/var/www/test/foo.txt&#8217;) was called but doesn&#8217;t have read access to foo.txt.

Strace can tell you what went wrong. E.g., if php doesn&#8217;t have read access to the file, strace will say &#8221;EACCESS (Permission denied)&#8221;. Or, if the <a class="zem_slink freebase/guid/9202a8c04000641f8000000000220ffa" href="http://en.wikipedia.org/wiki/Path_%28computing%29" title="Path (computing)" rel="wikipedia">file path you gave doesn&#8217;t exist, strace will say &#8221;ENOENT (No such file or directory)&#8221;, etc.

This works for any program you can run from the <a class="zem_slink freebase/en/command_line_interface" href="http://en.wikipedia.org/wiki/Command-line_interface" title="Command-line interface" rel="wikipedia">command-line, e.g., strace python myapp.py -e open,access…

Note: the above command uses php-cli, not mod_php, which is a different <a class="zem_slink freebase/en/server_application_programming_interface" href="http://en.wikipedia.org/wiki/Server_Application_Programming_Interface" title="Server Application Programming Interface" rel="wikipedia">SAPI with <a class="zem_slink freebase/en/diff" href="http://www.tracked.com/company/digg_inc/" title="Diff" rel="tracked">diff configs, etc.

  • <a href="http://www.commandlinefu.com/commands/view/5419/find-out-why-a-program-cant-seem-to-access-to-a-file">View this command to comment, vote or add to favourites
  • <a href="http://feeds2.feedburner.com/commands/by/rkulla">View all commands by <a href="http://feeds2.feedburner.com/commands/by/rkulla">rkulla

<a href="http://www.commandlinefu.com"><img align="bottom" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/header-logo.jpg" alt="" />

by David Winterbottom (<a href="http://codeinthehole.com">codeinthehole.com)

<a href="http://feedads.g.doubleclick.net/%7Ea/X6ezR4Ji3UJnWkl4rrMdt-zMUZw/0/da"><img align="bottom" src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/%7Ea/X6ezR4Ji3UJnWkl4rrMdt-zMUZw/0/di" alt="" />
<a href="http://feedads.g.doubleclick.net/%7Ea/X6ezR4Ji3UJnWkl4rrMdt-zMUZw/1/da"><img align="bottom" src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/%7Ea/X6ezR4Ji3UJnWkl4rrMdt-zMUZw/1/di" alt="" />

<img align="bottom" width="1" height="1" src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/%7Er/Command-line-fu/%7E4/Zlwqw2g-10c" alt="" />

URL: <a href="http://feedproxy.google.com/%7Er/Command-line-fu/%7E3/Zlwqw2g-10c/find-out-why-a-program-cant-seem-to-access-to-a-file">http://feedproxy.google.com/~r/Command-line-fu/~3/Zlwqw2g-10c/find-out-why-a-program-cant-seem-to-access-to-a-file<h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://blog.amit-agarwal.co.in/2010/04/12/visualizing-system-performance-data/">Visualizing system performance data (amit-agarwal.co.in) <li class="zemanta-article-ul-li"><a href="http://insidehpc.com/2010/03/17/io-profiling-of-mpi-apps/">IO profiling of MPI apps (insidehpc.com) <li class="zemanta-article-ul-li"><a href="http://www.slideshare.net/fabpot/symfony-components-3393116">Symfony Components (slideshare.net) <li class="zemanta-article-ul-li"><a href="http://www.skorks.com/2010/05/what-every-developer-should-know-about-urls/">What Every Developer Should Know About URLs (skorks.com) <li class="zemanta-article-ul-li"><a href="http://helpdeskgeek.com/databases/create-mysql-stored-routines-tips-tricks/">Creating MySQL Stored Routines for Non-DBAs – Part Three (helpdeskgeek.com) <div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/d00c0d37-773d-43e5-ac21-e9afbd6b2dd2/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_b78.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it