node daemon won't start with process.stdin.setRawMode(true) [duplicate] - node.js

This question already has answers here:
Input of Information into Javascript using terminal
(2 answers)
Closed 4 years ago.
I am running a node server daemon but I keep running into this error.
When I run my bash strip to test the application I get TypeError: process.stdin.setRawMode is not a function.
Can you help me find a way I can use keyboard input with this node application running in the background?
I have tried giving my bash script permissions chmod 777 x.sh & chmod 755 x.sh

setRawMode() is only available when the input is provided by a TTY and not like yours as direct stream from stdin.
Use this to check what stream you have:
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}

Related

Shell Script - Run shell commands in parallel in different bash sessions [duplicate]

This question already has answers here:
How do you run multiple programs in parallel from a bash script?
(19 answers)
Closed 2 years ago.
I have a requirement to run database restore commands in parallel from shell scripts. Both the commands should run in different bash sessions in parallel.
The following are the commands I need to run.
sudo su - $user -c "db2 RESTORE DATABASE ${SDBP} FROM '/dbnfs/db2main/backups/${DB2DBP}' TAKEN AT $TIMESTAMPP ON '/data1/DB2/tablespaces/${DB2DBP}' , '/data2/DB2/tablespaces/${DB2DBP}' DBPATH ON '/home/db2inst1' INTO ${DB2DBP} NEWLOGPATH '/data1/activelogs/${DB2DBP}' without rolling forward without prompting 2>&1"
sudo su - $user -c "db2 RESTORE DATABASE ${SDBS} FROM '/dbnfs/db2main/backups/${DB2DBS}' TAKEN AT $TIMESTAMPS ON '/data1/DB2/tablespaces/${DB2DBS}' , '/data2/DB2/tablespaces/${DB2DBS}' DBPATH ON '/home/db2inst1' INTO ${DB2DBS} NEWLOGPATH '/data2/activelogs/${DB2DBS}' without rolling forward without prompting 2>&1"
Let me know how to achieve it.
Since you want different bash sessions (perhaps due to long running commands), screen command might be of interest to you.
You can create new named screens (sessions), let's call it restore1 for the first command:
screen -S restore1
This will create a new screen. In this screen you can run your first command. Once command starts running, you can "detach" (ctrl+a d) from it.
Create another named screen called restore2 for SDBS:
screen -S restore2
Run the second command here, then detach from it. You can check the screens (sessions) by:
screen -list
You can reattach to any of the screens with screen -r <screen_name>, to check on the status of that command. Example:
screen -r restore1

Permission denied even with sudo [duplicate]

This question already has answers here:
How do I use sudo to redirect output to a location I don't have permission to write to? [closed]
(15 answers)
Closed 6 years ago.
Following this tutorial
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04
and trying to use the command
echo 'prefix=/usr/local' > node/etc/npmrc
however I get a permission denied error, even when using sudo.
Any ideas?
echo 'prefix=/usr/local' > node/etc/npmrc
however I get a permission denied error, even when using sudo.
You haven't shown us the failing command using sudo. Please update your question and show us the exact command that failed, along with the exact error message.
Meanwhile, I can guess that the failing command was:
sudo echo 'prefix=/usr/local' > node/etc/npmrc
That runs the echo command with root privileges (which is not particularly useful, since you can runecho as an ordinary user). The redirection is handled by your current shell process, and is subject to the permissions of the current user.
Since > is handled by the shell, you need a shell running as root to handle it:
sudo sh -c "echo 'prefix=/usr/local' > node/etc/npmrc"

Execute a command as a non super user in a sudo script [duplicate]

This question already has answers here:
Stop being root in the middle of a script that was run with sudo
(2 answers)
Closed 7 years ago.
I developed a script.
This script should called with sudo:
$ sudo ./script
In my script I have a command in the middle which I want to execute it as a non super user (like if it's executed without sudo)
Is it posssible to do that?
Technical it's possible with sudo -u plain_user command in your script. This way of scripting is somehow strange to me though.

bash: sudo: permission denied [duplicate]

This question already has answers here:
Use sudo to change file in root directory [duplicate]
(2 answers)
Closed 6 months ago.
VLC is running. Got the PID from pgrep vlc.
I want now to pause it manually since I would like it to run "submerged" (right now from another tty but probably as a daemon)
I tried to simply do sudo "pause" > /usr/bin/vlc/ having got the path by doing sudo ls -l /proc/<PID>/exe.
The answer is, even running the sudo command, that the permission is denied.
For my surprise, if I enter root mode sudo bash and just type the same command, the answer is not that the permission is denied, but rather that the "text file is busy". I'd like to guess what text file. I thought that command (in that case) inputted data to the command input manually (apart from writing to a text file)
This is probably what you want to do.
Write to /proc/pid of the program/fd/0. The fd subdirectory contains the descriptors of all the opened files and file descriptor 0 is the standard input (1 is stdout and 2 is stderr).
Example
Terminal 1:
[ciupicri#hermes ~]$ cat
Xxx
Terminal 2:
[ciupicri#hermes ~]$ pidof cat
7417
[ciupicri#hermes ~]$ echo xxx > /proc/7417/fd/0
Taken from another stack overflow answer

How to wait for user input in a terminal called with -e option? [duplicate]

This question already has answers here:
Prevent Gnome Terminal From Exiting After Execution [duplicate]
(4 answers)
Closed 9 years ago.
I'm trying to open gnome-terminal (though I think it would be related to any x-terminal-emulator) with a command provided using -e option, like gnome-terminal -e 'ls'. The terminal is closed as soon as the command is done working, so I need a way to wait for user input to be able to read the result and then finally close the window with Enter press.
I tried gnome-terminal -e 'ls; read -p "..."' and it works if I run ls; read -p "..." in an already opened terminal, but a terminal called with -e option keeps getting closed.
So is there any way to keep the terminal open until some user input is provided while using -e option?
Spawn a shell;
xterm -e bash -c 'ls; read -p "Press any key ..."'

Resources