Skip to content

Using Bash scripts on the fly is returning the script itself and the output within the response #104

@dalgharib

Description

@dalgharib

Hi Andrew,

I'm using ssh2shell in my project to execute several commands and bash scripts on a remote server, and ofcourse get each command response and use it in some analysis later.

What I`m facing is that, when executing the bash script on the remote server, I'm getting the response containing the script itself and the out put as well. I will post here part of the code to give more details about what is going on:

CODE HERE - ALL THE BELOW:

let host = { server: { host: config.host, port: config.port, userName: config.username, password: config.password, privateKey: config.privateKey, tryKeyboard: true, algorithms: algorithmObj, }, asciiFilter:"[^\r\n\x20-\x7e]", disableASCIIFilter:true, disableColorFilter:true, closedMessage:"Closed", debug:hostdebug, standardPrompt:">$%#", commands: [ bash -s ${fs.readFileSync('./script1.sh', 'utf-8')}`,
'Hello World',
'ls l'
],
idleTimeOut:30000,
showBanner: true,
window: true,

		onCommandComplete: async function( command, response,sshObj,stream) {                  
			const result.output=response;						
		},
	};

return new Promise(( resolve, reject ) => {

let SSH = new SSH2Shell(host),
callback = function(sessionText){                    
	resolve(commandResponses);                    
}

ssh2shellInstances.push(SSH);
SSH.on('error', reject);
SSH.connect(callback);

SSH.on ('emitCloseStream', function onClose(){                
	this.emit('closeStream');
});


SSH.on ('commandProcessing', function onCommandProcessing( command, response, sshObj, stream ) {
	this.on('closeStream',()=>{                        
			stream.close();
			ssh2shellInstances.pop();                        
	}) 
});`

Plz support on a way to get the response of bash script as its output only without the script itself after execution on the remote host.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions