很高兴有人可以提供帮助。
从终端将python脚本(a.py)插入Mysql(mydatabase / table1)时运行良好,但是作为cron作业运行时,无法插入或更新mysql(mydatabase / table1)。
a.py解析文档目录中的所有* .htm文件,并将结果lst_url插入到mydatabase / table1字段lst_url中。
a.py位于文档目录中。
cron作业是* * * * * document / a.py
谢谢。
Toh
CREATE PROCEDURE getRoomInfo()
BEGIN
DECLARE id1 INTEGER DEFAULT 0;
DECLARE id2 INTEGER DEFAULT 0;
DECLARE id3 INTEGER DEFAULT 0;
DECLARE price1 decimal(6,2) DEFAULT 0;
DECLARE price2 decimal(6,2) DEFAULT 0;
DECLARE price3 decimal(6,2) DEFAULT 0;
DECLARE done INTEGER DEFAULT 0;
DECLARE hotel_id INTEGER DEFAULT 0;
DECLARE cur_hotel CURSOR FOR SELECT hoteId FROM booking_rooms GROUP BY hoteId;
DECLARE cur1 CURSOR FOR SELECT id, price FROM booking_rooms WHERE totalAdults = 1 AND hoteId=hotel_id ORDER BY price;
DECLARE cur2 CURSOR FOR SELECT id, price FROM booking_rooms WHERE totalAdults = 2 AND hoteId=hotel_id AND totalChildren=1 ORDER BY price;
DECLARE cur3 CURSOR FOR SELECT id, price FROM booking_rooms WHERE totalAdults = 3 AND hoteId=hotel_id ORDER BY price;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
DROP TEMPORARY TABLE IF EXISTS combinations;
CREATE TEMPORARY TABLE combinations (hotelId INT, id VARCHAR(100), price DECIMAL(10,2)) ENGINE = Memory;
OPEN cur_hotel;
hotel_loop: LOOP
FETCH cur_hotel INTO hotel_id;
IF done=1 THEN
LEAVE hotel_loop;
END IF;
OPEN cur1; OPEN cur2; OPEN cur3;
cycle_loop: LOOP
FETCH cur1 INTO id1, price1;
FETCH cur2 INTO id2, price2;
FETCH cur3 INTO id3, price3;
IF done=1 THEN
set done=0;
LEAVE cycle_loop;
END IF;
INSERT INTO combinations(hotelId, id,price)
VALUES (hotel_id, CONCAT_WS(',',id1,id2,id3),price1+price2+price3);
END LOOP cycle_loop;
CLOSE cur1;
CLOSE cur2;
CLOSE cur3;
END LOOP hotel_loop;
CLOSE cur_hotel;
SELECT * FROM combinations;
DROP TEMPORARY TABLE combinations;
END
答案 0 :(得分:1)
Cron可以在其他python版本/环境中运行它。我会同时做Spinor8和Dan-Dev所说的,我会解释原因。
正如Spinor8所说,您可以在程序开头记录python版本。 Here's a great link explaining how.
如Dan-Dev所说,您应该定义要与shebang一起使用的python的路径。