웹에서 cron 설정하기
Ubuntu 17.04의 Nginx에서 확인했습니다.
php7.0-ssh2를 설치해야 합니다.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />
<script src="/js/jquery-3.2.1.min.js"></script>
<script src="cron_edit.js"></script>
<link href="cron_edit.css" rel="stylesheet">
<title>Cron Edit</title>
</head>
<body>
<h1>Cron Edit</h1>
<textarea name="text" id="text"></textarea>
<br />
<button id="submit">Submit</button>
<br />
<hr />
<div id="outarea_aa">outarea_aa</div>
<div id="outarea_bb">outarea_bb</div>
<div id="outarea_cc">outarea_cc</div>
<div id="outarea_dd">outarea_dd</div>
<div id="outarea_ee">outarea_ee</div>
<div id="outarea_ff">outarea_ff</div>
<div id="outarea_gg">outarea_gg</div>
<div id="outarea_hh">outarea_hh</div>
<hr />
Version: Jul/31/2017<p />
</body>
</html>
cron_edit.css
/* -------------------------------------------------------------- */
/*
cron_edit.css
Jul/31/2017
*/
/* -------------------------------------------------------------- */
#text {
width:640px;
height:400px;
}
button#submit {
width:200px;
height:30px;
}
/* -------------------------------------------------------------- */
cron_edit.js
// -----------------------------------------------------------------------
// cron_edit.js
//
// Jul/29/2017
//
// -----------------------------------------------------------------------
jQuery (function ()
{
jQuery("#outarea_aa").text ("*** cron_edit.js *** 開始 ***")
const url_php = "cron_fetch.php"
jQuery.get (url_php,function (data_rec)
{
jQuery("#text").text (data_rec)
submit_click_monitor ()
})
jQuery("#outarea_hh").text ("*** cron_edit.js *** 終了 ***")
})
// -----------------------------------------------------------------------
function submit_click_monitor ()
{
jQuery("button#submit").click (function ()
{
jQuery("#outarea_bb").text ("*** clicked ***")
const text_in = jQuery("#text").val ()
const url_php = "cron_update.php"
const args={"text": text_in}
jQuery.post (url_php,args,function (data_rec)
{
jQuery("#outarea_ff").html (data_rec)
})
})
}
// -----------------------------------------------------------------------
cron_config.php
<?php
// ----------------------------------------------------------------
//
// cron_config.php
//
// Jul/31/2017
//
// ----------------------------------------------------------------
date_default_timezone_set('Asia/Tokyo');
//
$host = "127.0.0.1";
$user = "scott";
$password = "tiger";
// ----------------------------------------------------------------
?>
cron_fetch.php
<?php
// ----------------------------------------------------------------
//
// cron_fetch.php
//
// Jul/31/2017
//
// ----------------------------------------------------------------
include "cron_config.php";
$connection = ssh2_connect($host, 22);
if($connection !== false){
$auth = ssh2_auth_password($connection, $user, $password);
ssh2_exec($connection, "crontab -l > /tmp/cron.txt");
$stream = ssh2_exec($connection, "cat /tmp/cron.txt");
stream_set_blocking($stream, true);
echo stream_get_contents($stream);
// ssh2_exec($connection, "exit");
}
// echo "*** cron_fetch.php *** end ***\n";
// ----------------------------------------------------------------
?>
cron_update.php
<?php
// ----------------------------------------------------------------
//
// cron_update.php
//
// Jul/31/2017
//
// ----------------------------------------------------------------
include "cron_config.php";
// ----------------------------------------------------------------
function file_write_proc ($string_out,$file_out)
{
$fp_out=fopen ($file_out,"w");
flock ($fp_out,LOCK_EX);
fputs ($fp_out,$string_out);
flock ($fp_out,LOCK_UN);
fclose ($fp_out);
chmod ($file_out,0666);
}
// ----------------------------------------------------------------
$file_out = "/tmp/cron_sent.txt";
if (isset ($_REQUEST['text']))
{
$string_out = $_REQUEST['text'];
// echo $string_out;
file_write_proc ($string_out,$file_out);
}
$connection = ssh2_connect($host, 22);
if($connection !== false){
$auth = ssh2_auth_password($connection, $user, $password);
$file_received = "/tmp/cron_received.txt";
$result = ssh2_scp_send ($connection,$file_out,$file_received);
echo "result = " . $result . "<br />";
$command = "crontab < " . $file_received;
echo $command . "<br />";
$result = ssh2_exec($connection, $command);
echo "result = " . $result . "<br />";
}
echo "*** cron_edit.php *** end ***\n";
// ----------------------------------------------------------------
?>
Reference
이 문제에 관하여(웹에서 cron 설정하기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ekzemplaro/items/90dd5f1fadd31bf94cac텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)