매주 월요일 새벽00:00에
php 파일을 하나 실행하려고 하는데요..
찾아보니
크론탭이라는게 있던데..
여기서
제가 원하는 소스
Copy
&& curl -sm 30 k.wdt.io/<email-address>/<cronjob-name>?c=0_0_*_*_mon
이걸 만들었습니다.
email-address 나 cronjob-name 이나 변경해야할것 같긴한데요;
문제는 이 소스를 어느 파일에 또 서버 어느위치에 넣느냐 인데..
도통 감이 안잡히네요-_-;;
하려는 작업은
매주 월요일 00:00 에 .php 파일 하나 실행하려고 합니다
전주 베스트회원을 뽑으려고 하거든요~
답변 2개 / 댓글 10개
채택된 답변
+20 포인트
얘기하신 crontab.guru 를 잠깐 살펴보았지만 저 또한 잘 이해되지 않았습니다.
다른 웹 크론 사이트를 하나 소개해 드리겠습니다.
계정 등록 후,
[Cronjobs] > [Create cronbjob]
으로 실행시키고자 하는 파일의 URL 과 스케쥴을 등록해주면 됩니다.
베스트회원을 뽑는 파일이 a.php 라면..
URL - http://~/a.php
Schedule - Monday, 0시, 0분으로 등록해주면 됩니다.
답변에 대한 댓글 6개
그렇습니다. 도메인/extend/a.php 와 같이 넣어주면 됩니다.
직접 브라우저 주소창에 붙여넣기 했을 때, 의도한 대로 실행된다면 유효한 URL 입니다.
크론에 의하지 않은 실행을 막는 방법은 여러가지가 있지만,
가장 간편한 방법중의 하나를 생각해 본다면,
URL 등록시 ~/extend/a.php?code=aabbccdd
와 같이 임의의 get 변수 처리형식으로 넣어준 후,
get 변수 값이 맞지 않으면 실행되지 않도록 처리해주는 방법이 있습니다.
그 외 referer 체크, Request 헤더 체크 등등 다양한 방법도 가능합니다.
직접 브라우저 주소창에 붙여넣기 했을 때, 의도한 대로 실행된다면 유효한 URL 입니다.
크론에 의하지 않은 실행을 막는 방법은 여러가지가 있지만,
가장 간편한 방법중의 하나를 생각해 본다면,
URL 등록시 ~/extend/a.php?code=aabbccdd
와 같이 임의의 get 변수 처리형식으로 넣어준 후,
get 변수 값이 맞지 않으면 실행되지 않도록 처리해주는 방법이 있습니다.
그 외 referer 체크, Request 헤더 체크 등등 다양한 방법도 가능합니다.
혹시 하나만 더 봐주실수 있나요...ㅎ
[code]
<?
if (!defined('_GNUBOARD_')) exit;
function get_best10_mb_list($write_row, $board, $skin_url, $subject_len=40) {
global $g5, $config;
global $qstr, $page;
global $name;
//$t = get_microtime();
// 배열전체를 복사
$list = $write_row;
unset($write_row);
$list_notice = array_map('trim', explode(',', $list['bo_notice']));
$list['is_notice'] = in_array($list['wr_id'], $list_notice);
if ($subject_len)
$list['subject'] = conv_subject($list['wr_subject'], $subject_len, '…');
else
$list['subject'] = conv_subject($list['wr_subject'], $list['bo_subject_len'], '…');
// 목록에서 내용 미리보기 사용한 게시판만 내용을 변환함 (속도 향상) : kkal3(커피)님께서 알려주셨습니다.
if ($list['bo_use_list_content'])
{
$html = 0;
if (strstr($list['wr_option'], 'html1'))
$html = 1;
else if (strstr($list['wr_option'], 'html2'))
$html = 2;
$list['content'] = conv_content($list['wr_content'], $html);
}
$list['comment_cnt'] = '';
if ($list['wr_comment'])
$list['comment_cnt'] = "<span class=\"cnt_cmt\">".$list['wr_comment']."</span>";
// 당일인 경우 시간으로 표시함
$list['datetime'] = substr($list['wr_datetime'],0,10);
$list['datetime2'] = $list['wr_datetime'];
if ($list['datetime'] == G5_TIME_YMD)
$list['datetime2'] = substr($list['datetime2'],11,5);
else
$list['datetime2'] = substr($list['datetime2'],5,5);
// 4.1
$list['last'] = substr($list['wr_last'],0,10);
$list['last2'] = $list['wr_last'];
if ($list['last'] == G5_TIME_YMD)
$list['last2'] = substr($list['last2'],11,5);
else
$list['last2'] = substr($list['last2'],5,5);
$list['wr_homepage'] = get_text($list['wr_homepage']);
$tmp_name = get_text(cut_str($list['wr_name'], $config['cf_cut_name'])); // 설정된 자리수 만큼만 이름 출력
$tmp_name2 = cut_str($list['wr_name'], $config['cf_cut_name']); // 설정된 자리수 만큼만 이름 출력
if ($board['bo_use_sideview'])
$list['name'] = get_sideview($list['mb_id'], $tmp_name2, $list['wr_email'], $list['wr_homepage'], $list['mb_nick']);
else
$list['name'] = '<span class="'.($list['mb_id']?'sv_member':'sv_guest').'">'.$tmp_name.'</span>';
$reply = $list['wr_reply'];
$list['reply'] = strlen($reply)*10;
$list['icon_reply'] = '';
if ($list['reply'])
$list['icon_reply'] = '<img src="'.$skin_url.'/img/icon_reply.gif" style="margin-left:'.$list['reply'].'px;" alt="답변글">';
$list['icon_link'] = '';
if ($list['wr_link1'] || $list['wr_link2'])
$list['icon_link'] = '<img src="'.$skin_url.'/img/icon_link.gif" alt="관련링크">';
// 가변 파일
if ($list['bo_use_list_file'] || ($list['wr_file'] && $subject_len == 255) /* view 인 경우 */) {
$list['file'] = get_file($list['bo_table'], $list['wr_id']);
} else {
$list['file']['count'] = $list['wr_file'];
}
if ($list['file']['count'])
$list['icon_file'] = '<img src="'.$skin_url.'/img/icon_file.gif" alt="첨부파일">';
// print_r ($board);
return $list;
}
function best_mb_group($skin_dir="", $rows=10, $best_mb_sort) {
global $g5;
$nowYmd = date("Y-m-d"); # 오늘시간을 구합니다.
$time = time();
$startYmd = date("Y-m-d",strtotime($day."-7day"));
if ($skin_dir) {
$latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
} else {
$latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
}
$list = array();
$sql = " SELECT * FROM {$g5['board_table']}";
$ress = sql_query($sql);
for($ii = 0; $board=sql_fetch_array($ress); $ii++){
$tmp_write_table = $g5['write_prefix'] . $board['bo_table']; # 게시판 테이블 전체이름
// 만약 메일을 활성화 시키고 싶으면 3번째 select 문에 wr_email 추가
if(empty($query))
{
$query = "SELECT temp4.mb_id, temp4.mb_nick AS wr_name, Total FROM ( SELECT mb_id, sum(Cnt) AS Total FROM ( SELECT * FROM ( SELECT mb_id, COUNT(*) AS Cnt FROM $tmp_write_table WHERE mb_id != 'admin' AND wr_datetime >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY AND wr_datetime < curdate() - INTERVAL DAYOFWEEK(curdate()) -1 DAY GROUP BY mb_id ";
}
// 만약 메일을 활성화 시키고 싶으면 3번째 select 문에 wr_email 추가
else
{
$query .= " UNION SELECT mb_id, COUNT(*) AS Cnt FROM $tmp_write_table WHERE mb_id != 'admin' AND mb_id != '' AND wr_datetime >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY AND wr_datetime < curdate() - INTERVAL DAYOFWEEK(curdate()) -1 DAY GROUP BY mb_id";
}
}
$query .= " ) AS TEMP ORDER BY temp.Cnt DESC ) AS temp2 GROUP BY temp2.mb_id) AS temp3 LEFT JOIN g5_member AS temp4 ON temp3.mb_id = temp4.mb_id ORDER BY Total DESC";
$link = $g5['connect_db'];
$result = @mysqli_query($link, $query);
//print_r ($query);
$board['bo_use_sideview'] = true;
for($i = 0; $row = sql_fetch_array($result); $i++){
$list[$i] = get_best10_mb_list($row, $board, $skin_dir, $wr_name);
}
ob_start();
include "$latest_skin_path/latest_mb.skin.php";
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>
[/code]
위 코드로 베스트맴버 구하려고 하는데요
크론탭에 등록한 파일도 이 파일이구요.
sql 문을 제가 작성하지 않아서
[code]
<?
if (!defined('_GNUBOARD_')) exit;
function get_best10_mb_list($write_row, $board, $skin_url, $subject_len=40) {
global $g5, $config;
global $qstr, $page;
global $name;
//$t = get_microtime();
// 배열전체를 복사
$list = $write_row;
unset($write_row);
$list_notice = array_map('trim', explode(',', $list['bo_notice']));
$list['is_notice'] = in_array($list['wr_id'], $list_notice);
if ($subject_len)
$list['subject'] = conv_subject($list['wr_subject'], $subject_len, '…');
else
$list['subject'] = conv_subject($list['wr_subject'], $list['bo_subject_len'], '…');
// 목록에서 내용 미리보기 사용한 게시판만 내용을 변환함 (속도 향상) : kkal3(커피)님께서 알려주셨습니다.
if ($list['bo_use_list_content'])
{
$html = 0;
if (strstr($list['wr_option'], 'html1'))
$html = 1;
else if (strstr($list['wr_option'], 'html2'))
$html = 2;
$list['content'] = conv_content($list['wr_content'], $html);
}
$list['comment_cnt'] = '';
if ($list['wr_comment'])
$list['comment_cnt'] = "<span class=\"cnt_cmt\">".$list['wr_comment']."</span>";
// 당일인 경우 시간으로 표시함
$list['datetime'] = substr($list['wr_datetime'],0,10);
$list['datetime2'] = $list['wr_datetime'];
if ($list['datetime'] == G5_TIME_YMD)
$list['datetime2'] = substr($list['datetime2'],11,5);
else
$list['datetime2'] = substr($list['datetime2'],5,5);
// 4.1
$list['last'] = substr($list['wr_last'],0,10);
$list['last2'] = $list['wr_last'];
if ($list['last'] == G5_TIME_YMD)
$list['last2'] = substr($list['last2'],11,5);
else
$list['last2'] = substr($list['last2'],5,5);
$list['wr_homepage'] = get_text($list['wr_homepage']);
$tmp_name = get_text(cut_str($list['wr_name'], $config['cf_cut_name'])); // 설정된 자리수 만큼만 이름 출력
$tmp_name2 = cut_str($list['wr_name'], $config['cf_cut_name']); // 설정된 자리수 만큼만 이름 출력
if ($board['bo_use_sideview'])
$list['name'] = get_sideview($list['mb_id'], $tmp_name2, $list['wr_email'], $list['wr_homepage'], $list['mb_nick']);
else
$list['name'] = '<span class="'.($list['mb_id']?'sv_member':'sv_guest').'">'.$tmp_name.'</span>';
$reply = $list['wr_reply'];
$list['reply'] = strlen($reply)*10;
$list['icon_reply'] = '';
if ($list['reply'])
$list['icon_reply'] = '<img src="'.$skin_url.'/img/icon_reply.gif" style="margin-left:'.$list['reply'].'px;" alt="답변글">';
$list['icon_link'] = '';
if ($list['wr_link1'] || $list['wr_link2'])
$list['icon_link'] = '<img src="'.$skin_url.'/img/icon_link.gif" alt="관련링크">';
// 가변 파일
if ($list['bo_use_list_file'] || ($list['wr_file'] && $subject_len == 255) /* view 인 경우 */) {
$list['file'] = get_file($list['bo_table'], $list['wr_id']);
} else {
$list['file']['count'] = $list['wr_file'];
}
if ($list['file']['count'])
$list['icon_file'] = '<img src="'.$skin_url.'/img/icon_file.gif" alt="첨부파일">';
// print_r ($board);
return $list;
}
function best_mb_group($skin_dir="", $rows=10, $best_mb_sort) {
global $g5;
$nowYmd = date("Y-m-d"); # 오늘시간을 구합니다.
$time = time();
$startYmd = date("Y-m-d",strtotime($day."-7day"));
if ($skin_dir) {
$latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
} else {
$latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
}
$list = array();
$sql = " SELECT * FROM {$g5['board_table']}";
$ress = sql_query($sql);
for($ii = 0; $board=sql_fetch_array($ress); $ii++){
$tmp_write_table = $g5['write_prefix'] . $board['bo_table']; # 게시판 테이블 전체이름
// 만약 메일을 활성화 시키고 싶으면 3번째 select 문에 wr_email 추가
if(empty($query))
{
$query = "SELECT temp4.mb_id, temp4.mb_nick AS wr_name, Total FROM ( SELECT mb_id, sum(Cnt) AS Total FROM ( SELECT * FROM ( SELECT mb_id, COUNT(*) AS Cnt FROM $tmp_write_table WHERE mb_id != 'admin' AND wr_datetime >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY AND wr_datetime < curdate() - INTERVAL DAYOFWEEK(curdate()) -1 DAY GROUP BY mb_id ";
}
// 만약 메일을 활성화 시키고 싶으면 3번째 select 문에 wr_email 추가
else
{
$query .= " UNION SELECT mb_id, COUNT(*) AS Cnt FROM $tmp_write_table WHERE mb_id != 'admin' AND mb_id != '' AND wr_datetime >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY AND wr_datetime < curdate() - INTERVAL DAYOFWEEK(curdate()) -1 DAY GROUP BY mb_id";
}
}
$query .= " ) AS TEMP ORDER BY temp.Cnt DESC ) AS temp2 GROUP BY temp2.mb_id) AS temp3 LEFT JOIN g5_member AS temp4 ON temp3.mb_id = temp4.mb_id ORDER BY Total DESC";
$link = $g5['connect_db'];
$result = @mysqli_query($link, $query);
//print_r ($query);
$board['bo_use_sideview'] = true;
for($i = 0; $row = sql_fetch_array($result); $i++){
$list[$i] = get_best10_mb_list($row, $board, $skin_dir, $wr_name);
}
ob_start();
include "$latest_skin_path/latest_mb.skin.php";
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>
[/code]
위 코드로 베스트맴버 구하려고 하는데요
크론탭에 등록한 파일도 이 파일이구요.
sql 문을 제가 작성하지 않아서
저 같은 경우는 저 명령을 실행하는 php 파일을 만들어서 (system, exec 같은 함수 사용)
/var/www/html 폴더에 넣어두고
wget 으로 localhost에 있는 그 php 파일을 실행하도록 하는데
이게 사실 좋은 방법인지는 모르겠습니다 ㅎ
답변에 대한 댓글 4개
답변을 작성하려면 로그인이 필요합니다.
extend 폴더에 있는 파일을 실행하려고 하는데요.
도메인/extend/a.php
하면 되는건가요..!?
메인에서 a.php를 참조하는 스킨파일이 실행되는건 어떻게 막아야하죠!!??
읔..