We can test if a directory is writable by the uid of the current process:
if [ -w $directory ] ; then echo 'Eureka!' ; fi
But can anyone suggest a way to test if a directory is writable by some other uid?
My scenario is that I am administering a MySQL Server instance, and I want to change the location of the slow-query log file temporarily. I can do this by executing a MySQL command SET GLOBAL slow_query_log_file='$new_log_filename'
and then disable & enable query logging to make mysqld
start using that file.
But I'd like my script to check that the uid of the mysqld
process has permissions to create that new log file. So I'd like to do something like (pseudocode):
$ if [ -w-as-mysql-uid `basename $new_log_filename` ] ; then echo 'Eureka!' ; fi
But of course that's an imaginary test predicate.
Clarification: I would like a solution that doesn't rely on su
because I can't assume the user of my script has su privilege.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…