Find out why a program can't seem to access to a file
$ 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’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(’/var/www/test/foo.txt’) was called but doesn’t have read access to foo.txt.
Strace can tell you what went wrong. E.g., if php doesn’t have read access to the file, strace will say ”EACCESS (Permission denied)”. 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’t exist, strace will say ”ENOENT (No such file or directory)”, 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">
Related Articles:
- 2010/04/28 String and Array Creation
- 2010/03/28 Search & replace with find & ed
- 2010/04/06 vim understanding the various modes and using the yanking more efficiently.
- 2010/03/25 vim search multiple files
- 2010/03/24 Recursive Regular Expressions