"PHP crontab 보여주기"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 10개는 보이지 않습니다)
1번째 줄: 1번째 줄:
;PHP crontab 보여주기
;<nowiki>PHP: List root's crontab with sudo</nowiki>
;must be privileged to use -u
;<nowiki>sudo: sorry, you must have a tty to run sudo</nowiki>
;아파치 PHP crontab 보여주기


==방법 1: apache계정의 크론탭==
==방법 1: apache 계정의 크론탭==
<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
exec('crontab -l 2>&1', $output);
exec('crontab -l 2>&1', $output);
12번째 줄: 15번째 줄:
#    [0] => no crontab for apache
#    [0] => no crontab for apache
# )
# )
</source>
</syntaxhighlight>


==방법 2: root계정의 크론탭==
==방법 2: root 계정의 크론탭==
<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
exec('crontab -l -uroot 2>&1', $output);
exec('crontab -l -uroot 2>&1', $output);
25번째 줄: 28번째 줄:
#    [0] => must be privileged to use -u
#    [0] => must be privileged to use -u
# )
# )
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
exec('sudo crontab -l -uroot 2>&1', $output);
exec('sudo crontab -l -uroot 2>&1', $output);
36번째 줄: 39번째 줄:
#    [0] => sudo: sorry, you must have a tty to run sudo
#    [0] => sudo: sorry, you must have a tty to run sudo
# )
# )
</source>
</syntaxhighlight>
<source lang='cli'>
*[[sudoers]] 수정
[root@jmnote ~]# vi /etc/sudoers
<syntaxhighlight lang='console'>
</source>
[root@zetawiki ~]# vi /etc/sudoers
<source lang='text' highlight='2'>
</syntaxhighlight>
<syntaxhighlight lang='text' highlight='2,5'>
Defaults    requiretty
Defaults    requiretty
Defaults:apache !requiretty
Defaults:apache !requiretty
</source>
... (생략)
<source lang='php'>
root ALL=(ALL) ALL
apache ALL=NOPASSWD:/usr/bin/crontab
</syntaxhighlight>
<syntaxhighlight lang='php'>
<?php
<?php
exec('sudo crontab -l -uroot 2>&1', $output);
exec('sudo crontab -l -uroot 2>&1', $output);
52번째 줄: 59번째 줄:
# Array
# Array
# (
# (
#    [0] => sudo: no tty present and no askpass program specified
#    [0] => 0 12 * * * php /var/www/batch/my_batch.php
#    [1] => 35 * * * * python /root/pywikipedia/redirect.py double -always
#    [2] =>
# )
# )
</source>
</syntaxhighlight>
<source lang='cli'>
[root@jmnote ~]# grep apache /etc/passwd
apache:x:48:48:Apache:/var/www:/sbin/nologin
</source>
<source lang='cli'>
[root@jmnote ~]# sed -i 's/\/sbin\/nologin/\/bin\/bash/g' /etc/passwd
[root@jmnote ~]# grep apache /etc/passwd
apache:x:48:48:Apache:/var/www:/bin/bash
</source>


==같이 보기==
==같이 보기==
*[[crontab]]
*[[crontab]]
*[[/etc/sudoers]]


==참고 자료==
==참고==
*http://stackoverflow.com/questions/11107332/php-list-roots-crontab-with-sudo
*http://stackoverflow.com/questions/11107332/php-list-roots-crontab-with-sudo


[[분류: PHP]]
[[분류: PHP]]

2020년 11월 2일 (월) 02:34 기준 최신판

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 }}