Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I have this shell (bash) command on linux. I want to make this happen in Windows .bat (CMD).
Linux command:
export STATUS="$(cat STATUS_FILE)-${STATUS_CODE:-0}"
STATUS_FILE contains status of the current server. You can say -for example- "running".
STATUS_CODE is the status code of the server. If it given, it is bigger than 1. If this env not available then 0 as default.
So the output and STATUS will be: running-0 or running-2
I know environments can be translated as %STATUS_CODE% but how do I read from status file without newline (one line text stripped if any) and assign it to new variable called $STATUS together with the code.
This worked for me for now:
set /p FSTATUS=<STATUS_FILE
SET STATUS=%FSTATUS%-%STATUS_CODE%
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I have created an image of my sd card containing raspbian using the dd tool. This gave me a 16,09 GB big image file. The actual data on there is about 5gb, and I want to truncate it so I can store/clone it onto a 8gb sd card.
All help results I found required Linux to do this (tools like resize2fs doesn't appear to be available for osx, at least, can't find it with homebrew).
What tool(s) can I use to remove the 'empty' space of my .img file?
If you just created it using dd, it is just a dump with no filesystem-specific interpretation, so you can just as easily use dd to get the first 6GB or so:
dd if=Existing16GBimage.img of=New6GBimage.img bs=1m count=6000
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
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
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
After connection to the ssh you get a welcome message that is fed by /etc/motd. Now I would like to have those messages per user but I am not allowed to edit /etc/motd.
So I wonder if there is something possible with ~/.ssh/motd so that those messages will be stored in the users dir. This would be great because every user shall have it's own instructions for the given path-structure.
Does someone know how to solve this?
Thanks in advance!
The "Message of the day" is a cheap way to send a message to all users. If you want to target individual users, you have these options:
Send them an email.
Edit the login script (look into /etc/profile for Bourne shells) and add a line which looks for a per-user message in a certain path and which displays that. Example:
test -e /var/motd/$LOGNAME && cat /var/motd/$LOGNAME
The second approach has the advantage that you can define which path is used (so you can use one which you can write; if you can't write /etc/motd, then you can't edit anything in ~/.ssh/ either).
You will need to be root to set this up this, of course.
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 &