Redirecting input of an interactive script [closed] - bash

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I want to redirect input of an interactive program/script to a different program. I did with nc in the following way.
Bash 1
nc -nlvp 100 | script
Bash 2
nc 127.0.0.1 100
It works, but are there any better ways? Can I redirect input of an interactive script without nc/sockets?

If you know the PID of the process you want to send characters to over stdin, then simply write to /proc/$pid/fr/0. Example:
Shell 1:
$ cat
Shell 2:
$ pidof cat
12345
$ cat > /proc/12345/fd/0
hello
Result in Shell 1:
hello

Related

What is the difference between 'ls --color' and 'ls --color=tty'? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am making an alias for ls in my .zshrc profile so that it always has a colored output. As it turns out, I stumbled across either
alias ls="ls --color=tty"
or, without the tty value
alias ls="ls --color"
Is there any particular situation where either the commands $ ls --color=tty and $ ls --color, or the above aliases, can behave differently ?
With no argument attached to the option (--color), the output is always colorized. With --color=tty, it is only colorized when stdout is connected to a tty. This matters when the output of ls is piped or redirected.

Linux mint terminal output disappearing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I'm running a script on terminal and it is supposed to produce a long output, but for some reason the terminal is just showing me the end of the result and I cannot scroll up to see the complete result. Is there a way to save all the terminal instructions and results until I type clear.
The script I'm using has a loop so I need to add the output of the loop if Ill be redirecting the output to a file.
Depending on your system, the size of the terminal buffer may be fixed and hence you may not be able to scroll far enough to see the full output.
A good alternative would be to output your program/script to a text file using:
user#terminal # ./nameofprogram > text_file.txt
Otherwise you will have to find a way to increase the number of lines. In some terminal applications you can go to edit>profiles>edit>scrolling tab and adjust your settings.
You can either redirect the output of your script in a file:
script > file
(Be careful to choose a file that does not exist otherwise the content will be erased)
Or you can buffer the output with less:
script | less

Shell show same files in the same path? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I got two output folders when I type ls -l on shell.
MyBookLive:~/download/# ls -l
drwxrwxrw- 4 root root 65536 2013-12-20 12:33 output
drwxrwxrw- 3 root root 65536 2013-12-20 12:33 output
And I am sure there is no spaces in filename, because when I hit tab key, it shows:
MyBookLive:~/download/# ls -l output
output/ output/
Why? Thanks.
The second "output" has character 129 after the last "t".
Try this in your browser's console, copying the "output/ output/" string from your question.
"output/ output/".split('').forEach(function(x){console.log(x, x.charCodeAt(0))})

Log file pattern matching [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
i want to monitor application log file for specific error patterns on content added in since last 10 min (or since script last run) please not i dont want to monitor entire log file but only lines that are added in last 10 min, when patern is matched i want it displayed on screen. I'm confused how to achieve this thru script.
TIA
regards
tnt5273
FILE=logfile
lines=$(wc -l < "$FILE")
while sleep 600; do
clines=$(wc -l < "$FILE")
diff=$(($clines - $lines))
tail -$diff $FILE | grep PATTERN
lines=$clines
done
What you appear to be describing is commonly achieved at a console by:
tail -F /path/to/my/file | grep "pattern"
This an idiom used by many system adminstrators.
There's another approach where you want to be alerted if a particular event is logged, but you don't want to watch for it.
The Simple Event Correllator is a perl script designed to watch logs, correlate events and perform actions.

What is the exact use of & in shell scripting? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm very new to shell scripting. I have a basic doubt of what is the use of & in shell scripting? That is doing something like this :
commands arg &
Waits to give more input. But what is its exact use? How should I use it in real world?
As you have used it there, it runs commands arg in the background, disconnected from your keyboard, and the shell immediately asks you for its next command.
As for the real world, I use it when I have a command that will take some significant time to run but does not require any input from me and will put all of its output into a file, for example
# walk through the whole filesystem looking for a particular filename
find / -name 'obscure.filename' -print > /tmp/found-it &

Resources