Suppose I have the following bash script
#! /usr/bin/env bash
echo $1
dir_var="/Users/username/Desktop"
new_dir="node_shell"
echo "Changing to Desktop directory"
cd $dir_var
echo "Creating a new folder"
mkdir -p $new_dir
and I execute the script with the following method
create_fs_account_1: (user_name, callback) ->
console.log "Calling script execution"
sh = spawn('sh', [user_name])
fs.createReadStream('public/shell_scripts/shell_test.sh').pipe(sh.stdin)
console.log("Just read the script file")
sh.stdout.on 'data', (data) ->
console.log "New data " + data
sh.on 'exit', (code) ->
console.log "script ended with code " + code
callback code
When I execute the method I get the following error
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: EPIPE, Broken pipe
at Socket._writeImpl (net.js:159:14)
at Socket._writeOut (net.js:444:25)
at Socket.write (net.js:377:17)
at [object Object].ondata (stream.js:36:26)
at [object Object].emit (events.js:64:17)
at [object Object]._emitData (fs.js:916:10)
at afterRead (fs.js:898:10)
at wrapper (fs.js:245:17)
I have also noticed that when there is no error, the script doesn't really execute. the side effect I am expecting is not there. Can somebody explain to me what I am doing wrong between the script and the node.js (coffee script) code?
thanks in advance
2. Why don't you spawn the script?
> span('sh', [ 'public/....', user_name ])
3. Why do you cd to $dir_var if you mkdir -p?
> mkdir -p $dir_var/$new_dir
Hope it helps :)
---
Diogo R.
It'd be better to do something like this:
spawn("bash", ["public/shell_scripts/shell_test.sh"])
or even:
spawn("bash", ["public/shell_scripts/shell_test.sh"],
{ cwd: "/Users/username/Desktop", uid: <username uid> })
(And yes, you'll get better responses if you post examples in native
js rather than a to-js language.)
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
Anyway, let me compile my code in javascript and get back to the group
Note that ssh takes an argument which is the command to run on the
remote server, so you could do this pretty easily in the same way.
spawn("ssh", ["user@remotehost", "chdir blah && ls"])
> The actual scripts will be ssh commands.
In that case, you might be interested in existing modules for dealing with ssh, like:
https://github.com/FlashFan/NodeSSH