update
This commit is contained in:
19
index.js
19
index.js
@@ -3,6 +3,7 @@ const app = express();
|
|||||||
const port = 3000;
|
const port = 3000;
|
||||||
const cron = require("node-cron");
|
const cron = require("node-cron");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
const { exec } = require("child_process");
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.json("Scheduler App");
|
res.json("Scheduler App");
|
||||||
@@ -42,6 +43,24 @@ cron.schedule(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cron.schedule("* * * * *", async () => {
|
||||||
|
exec(
|
||||||
|
'bash /home/script/script.sh',
|
||||||
|
(error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(`Gagal menjalankan script: ${error.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stderr) {
|
||||||
|
console.error(`Stderr: ${stderr}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Output: ${stdout}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
res.json("What are you looking for?!");
|
res.json("What are you looking for?!");
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user