shell运行python脚本,nodejs执行shell脚本
在项目中使用了定时执行shell命令的功能:
//runShell.js
const process=require (child _ process );
请求(colors );
module.exports=(sh,log=',callback ) }
罗格!=='? console.log (` [ shell log ] `.green,log ) : null;
console.log(`[ SH ]`.cyan,sh.cyan;
process.exec(sh,(err,sto )={
if(err ) {
console.log ` [ shell error ] `.red,err;
返回
}
罗格!=='? console.log ` [ shell log ] `.green,log,' success ' ) : null;
console.log(sto;
callback () )
() )
}
//壳牌. js
constasync=require(async );
constmoment=require('moment );
construn=require('./run ' );
请求(colors );
async.waterfall (甜杯子/p(next )={
console.log (' # # # # # export users # # # # # # ' );
console.log(starttime: (,moment ).format ) yyyy-mm-DDhh:mm:ss ) )
next (;
(,
(next )={
mongo import-h 127.0.0.1336027017-dxxx-c users-- file/var/www/XXX.JSON-- up sert ','导出文件'
(,
],(err )={
console.log(endtime: (,moment ).format (yyyy-mm-ddhh : mm : ss ) )
if(err ) {
console.log ` [ exportusersshellerror ] `.red,err;
}
() )