Javascript/Nodejs执行shell脚本和pass变量

Javascript/Nodejs执行shell脚本和pass变量,javascript,node.js,bash,shell,Javascript,Node.js,Bash,Shell,我需要在我的项目中执行一些shell脚本: restoreBackup(timestamp) { return runCommand(`backup_restore.sh ${timestamp}`); }, 时间戳必须以unix时间戳的形式传递给脚本。 e、 g.1513252423 设置或传递时间戳: restoreBackup(timestamp,callback) { backup.restoreBackup(timestamp) .then(callback)

我需要在我的项目中执行一些shell脚本:

restoreBackup(timestamp) {
  return runCommand(`backup_restore.sh ${timestamp}`);
},
时间戳必须以unix时间戳的形式传递给脚本。 e、 g.1513252423 设置或传递时间戳:

restoreBackup(timestamp,callback) {
    backup.restoreBackup(timestamp)
      .then(callback)
      .catch(err => callback(err));
  }
问题是我当前的解决方案不起作用,它是从我直接在bash上使用的调用派生出来的。时间戳不会作为unix时间传递,而是转换为字符串,这是节点控制台中的输出:

Running cmd: /home/essentim/manager/scripts/backup_restore.sh Thu Dec 14 2017 11:53:43 GMT+0000 (UTC)
error handler:
"/bin/sh: 1: Syntax error: \"(\" unexpected"

你知道如何解决这个问题吗?

这是我的解决方法,现在正在使用

restoreBackup(timestamp) {
    timename = new Date(timestamp).getTime()/1000;
    return runCommand(`backup_restore.sh ${timename}`);
  },
摘自:


Thx

您能记录您的时间戳并显示吗?我不知道我是否明白,您所说的“我当前的解决方案不起作用”是什么意思?您传递的是什么时间戳,该命令接收的是什么时间戳?问题是${timestamp}似乎没有传递unix时间戳,它会在其中生成一个类似“2017年12月14日1X:XX:XX”的字符串。显示设置时间戳值的代码。然后显示调用的时间戳的值,以及在函数中得到的值。restoreBackup(timestamp,callback){backup.restoreBackup(timestamp).Then(callback.catch(err=>callback(err));}