PHP crontab 보여주기

PHP: List root's crontab with sudo
must be privileged to use -u
sudo: sorry, you must have a tty to run sudo
아파치 PHP crontab 보여주기

1 방법 1: apache 계정의 크론탭[편집]

<?php
exec('crontab -l 2>&1', $output);
echo '<xmp>';
print_r( $output );
echo '</xmp>';
# Array
# (
#     [0] => no crontab for apache
# )

2 방법 2: root 계정의 크론탭[편집]

<?php
exec('crontab -l -uroot 2>&1', $output);
echo '<xmp>';
print_r( $output );
echo '</xmp>';
# Array
# (
#     [0] => must be privileged to use -u
# )
<?php
exec('sudo crontab -l -uroot 2>&1', $output);
echo '<xmp>';
print_r( $output );
echo '</xmp>';
# Array
# (
#     [0] => sudo: sorry, you must have a tty to run sudo
# )
[root@zetawiki ~]# vi /etc/sudoers
Defaults    requiretty
Defaults:apache !requiretty
... (생략)
root	ALL=(ALL) 	ALL
apache	ALL=NOPASSWD:/usr/bin/crontab
<?php
exec('sudo crontab -l -uroot 2>&1', $output);
echo '<xmp>';
print_r( $output );
echo '</xmp>';
# Array
# (
#     [0] => 0 12 * * * php /var/www/batch/my_batch.php
#     [1] => 35 * * * * python /root/pywikipedia/redirect.py double -always
#     [2] => 
# )

3 같이 보기[편집]

4 참고[편집]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}