I have a shell script named containerLaunch.sh
that looks like this
#!/bin/bash
echo "Creating container.."
lxc launch ubuntu:18.04 $1
lxc exec $1 -- sudo --user ubuntu --login
I deploy this script using Node.js via the exec function:
var containerName = req.query.name;
const myShellScript = exec('sh ./containerLaunch.sh ' + containerName);
myShellScript.stdout.on('data', (data)=>{
console.log(data);
});
myShellScript.stderr.on('data', (data)=>{
console.error(data);
});
But, it simply runs the first echo command and not any of the other lxc commands.
Interestingly, directly running the shell file by doing sh ./containerLaunch.sh test
, it seems to work.
What is causing this and how do I fix it?