NodeJS - Run shell command, exit, transfer to shell command - node.js

I want to make a easy Buttonboard in the terminal with node and "blessed" for connection or running different commands.
-----------------------------------------------
_____________________ ___________________
| Run cleanup.sh | | ssh to server1 |
_____________________ ___________________
_____________________ ___________________
| Git sync | | ssh to server2 |
...
I want to click on a Button and the node script runs the command, as example "ssh 10.10.10.10".
The script should exit and I want to be on the server like I would with just running "ssh 10.10.10.10".
Is this possible with nodejs?
The Blessed Script for the buttons is ready, I just don't know how to handle the rest.

use shellJS package with shell.exec() method.
https://github.com/shelljs/shelljs
Handle your script to terminate after each action, like ssh or run sh script.

Related

Using SSH with expected user input for picking an environment on the server

I am working on a script in linux in which i need to SSH to another server.
I am using this syntax ssh user#ip
When doing a manual SSH when we type "ssh user#ip" a few second, a second prompt will show and ask what environment are we choosing ex 1 to 4
(4) - this is the number of the environment i will be choosing.
But when doing ssh user#ip 4 - error received (bash command not found)
Here is the image on what is the prompt when using ssh
Without knowing what happens after you select the environment, its probably something like:
echo 4 | ssh user#ip
Feed 4 to whatever is prompting for environment, then exit.
If you need to stay connected, then something like
echo 4 | ssh -tt user#ip "ksh -l"
ksh -l could be replaced by some other shell or command like vi foo.txt (here when the command exits, the connection closes).
The above is similar to this previous question:
Run ssh and immediately execute command

What directory shell commands in Jenkins execute in?

I am looking at various Jenkins projects which have shell commands being executed as part of the build process. They are referencing and modifying variables that are not defined anywhere in the project.
I am trying to figure out what environment these shell scripts are being executed in. I read the JenkinsWiki but it did not really explain what the PWD of the shell during processing of a particular Jenkins job. Googling jenkins directory structure yields results which are mostly concerned with the internals of Jenkins itself, not the execution environment of my build jobs. What directory shell commands in Jenkins execute in?
You can find the current working directory of a process using the proc subsystem:
# Get the PID using something like this:
PID=$( ps -o pid,cmd | grep jenkin[s] | awk '{print $1}' | head -n 1 )
# Use the proc subsystem
ls -l /proc/$PID/cwd

How to perform ps on several machines to supervise their performance

I want to supervise the performance of the specified process on several machines. I want to perform
ps -eo pcpu,pmem,resident,cutime,cstime,utime,cmd | grep -v grep | grep processToBeSupervised
on several machines every 10 second since the supervise job to be launched for 100 seconds and return the standard output of these machine to one of the machine. So the script should be like this:
for i in 1 2 3 4 5 6 7 8 9 10
do
ps -eo pcpu,pmem,resident,cutime,cstime,utime,cmd | grep -v grep | grep processToBeSupervised
echo "--"
sleep 10
done
For example there are 5 machines, A, B, C, D, and E. A launches the supervise job and after 100 second the report of A, B, C, D, and E should be returned and be stored on A's specified folder.
How should I write this. I just don't know how to give commands from one machine to others.
You could use ssh with public/private keys set up.
Make a bash script in linux such as "script.sh"
execute ps command on machine A
ssh to machine B and collect output of machine B
ssh root#machineB your ps command
ssh to machine C and collect output of machine C
ssh root#machineC your ps command
ssh to machine D and collect output of machine D
ssh root#machineD your ps command
ssh to machine E and collect output of machine E
ssh root#machineE your ps command
execute it from terminal
./script.sh | tee A's specified folder
put this script.sh | tee A's specified folder to crontab to execute supervise job automatically after specified time.
You could also have the machines exec the ps command and show it on a secure web page, and have machine A wget from these machines.

Bash script execute command on multiple servers

I'm trying to login into multiple servers and execute the following command:
arp -an|grep lanx>lanx
I'm using this method:
ssh admin#10.x.x.x arp\ -an|grep\ lanx >lanx
but it is not working its giving me an error
ideally just put the commands in quotes like this:
ssh admin#10.x.x.x '/sbin/arp -an | grep lanx' > lanx
or
ssh admin#10.x.x.x '/sbin/arp -an' | grep lanx > lanx
The other problem might be the user admin on your machine does not have arp in PATH (is he root? arp is usually in /sbin/ and /sbin/ is usually not in PATH of a regular user.
put in subshell. something like this will make things more clear:
(ssh xxxx arp -an) | grep lanx > /tmp/lanx

How do I execute a Perl program on a remote machine?

I wrote a Perl program to capture a live data stream from a tail command on a Linux machine using the following command in the console:
tail -f xyz.log | myperl.pl
It works fine. But now I have to execute this Perl program on a different machine because the log file is on that different machine. Can anyone tell me how I can do it?
You could say
ssh remotemachine tail -f xyz.log | myperl.pl
I suppose or maybe mount the remote log directories locally onto your administrative machine and do the processing there.
Or you could even say
ssh remotemachine bash -c "tail -f xyz.log | myperl.pl"
in order to run the script on the remote machine (if your script produces some output files and you want them on remote machine)

Resources