我有一个脚本可以运行一些基于用户的git
命令npm
#!/bin/sh
/bin/su someuser -c "
cd /opt/app1/;
env -i git remote update;
env -i git pull origin dev;
cd /opt/app1/client/;
npm run build;
"
git
命令运行正确。该npm
命令运行并构建文件,但会引发很多关于
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 8.x
Found bindings for the following environments:
- Linux 64-bit with Node.js 9.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.
如果我npm run build
从终端以用户身份运行,则一切正常。我什至在脚本中尝试过env -i npm run build
,这只是说env: ‘npm’: No such file or directory
。所以我然后尝试env -i /usr/local/bin/npm run build
并奇怪地返回了/usr/bin/env: 'node': No such file or directory
。
我虽然这user -c
会给我设置所有环境,就像用户登录一样,env -i
这会让我env
在没有父母的情况下保持干净。
也试过:
#!/bin/sh
/bin/su someuser - -c "
cd /opt/app1/;
git remote update;
git pull origin dev;
cd /opt/app1/client/;
npm run build;
"
最后一次尝试返回与第一次相同:git 命令正常工作,构建抛出关于 sass 和环境的错误,就好像我从终端以用户身份运行命令时有所不同。
知道为什么这个命令不能正常工作吗?