io-redirection

How to stop redirection via exec

How to stop redirection via exec I want to redirect some output of a script to a file. REDIRECT_FILE="foo.txt" echo to console # starting redirect exec > $REDIRECT_FILE echo to file echo … echo … # stop redirect exec >&- echo end of script "end of script" should be written to stdout. But instead there …

Total answers: 1

Print on stdout and log with logger

Print on stdout and log with logger I have a bash script with several "echo STRING" commands. I would like to log STRING with logger but still print it on stdout. echo STRING | logger obliviously does not do it. EDIT: echo STRING | tee >(logger) does it. >(COMMAND) is a process substitution, it substitutes …

Total answers: 2

How to pass the standard input of a shell script to a background command

How to pass the standard input of a shell script to a background command In a shell script, I am trying to start a background command that has the same stdin as that of the shell script. #!/bin/sh # … the-program & However, the-program above will not have access to the same standard input as …

Total answers: 1

tee /dev/stderr inside script truncates output file if you redirect stderr

tee /dev/stderr inside script truncates output file if you redirect stderr Given a script like below if I try to redirect stderr to a file, then the file is truncated at the point tee is used: $ cat test.sh #!/bin/bash set -eux echo before echo ‘{ "foo": "bar" }’ | tee /dev/stderr | jq .foo …

Total answers: 2

how to execute command and log only the command to a file

how to execute command and log only the command to a file I’m trying to run a command and log only the command to a file. I’ve tried using exec 4>test|command >&4|exec 4>&- but doesnt’ work. If I run the commands separately it works but only records the output of the command, the same with …

Total answers: 1

Redirect stderr to stdout to a file in a script

Redirect stderr to stdout to a file in a script I have several different algorithms, that I need to prototype. So I make prototype programs and a script. the script called time.sh looks like this echo "Timing algorithm1:" time algo1 >dev/null echo "Timing algorithm2:" time algo2 >dev/null echo "Timing algorithm3:" time algo3 >dev/null … Now …

Total answers: 3

Portable temporary file descriptors inside `sh -c`

Portable temporary file descriptors inside `sh -c` cat <(echo yes) Displays "yes". And running this inside sh -m results in the same thing on Bash 5.2.15. Yet on Bash 4.4.20 it throws an error: sh -c "cat <(echo yes)" sh: -c: line 0: syntax error near unexpected token `(‘ Why the error? Are there any …

Total answers: 1

Why Bash redirects even when there's no command?

Why Bash redirects even when there's no command? The Bash manual says that, after performing expansions If no command name results, redirections are performed, but do not affect the current shell environment. Now, what’s a use-case for this? What’s the point of redirecting if there’s nothing to do, and the redirection don’t even affect the …

Total answers: 2

Can't create a SSL certificate. [bash:server.key:Permission Denied]

Can't create a SSL certificate. [bash:server.key:Permission Denied] i’m a student and i’m trying to make a SSL certificate because i’m following this guide: https://www.server-world.info/en/note?os=Fedora_27&p=httpd&f=13 I’m running in vbox Fedora Server 38 I got this output: [wlima@wlimaserver certs]$ sudo umask 77 ; /usr/bin/openssl genrsa -aes128 2048 > server.key [sudo] password for wlima: bash: server.key: Permission denied …

Total answers: 1

retrieve std out redirect to /dev/null

retrieve std out redirect to /dev/null is there a way to retrieve std out redirected to /dev/null? I tried tail -f /proc/{PID}/fd/1, looks like only works except redirects to /dev/null. i.e. tail -f /proc/${cmd_pid}/fd/1 works on cmd > log.txt but not cmd > /dev/null ————update———— in fact, my problem is log.txt will be quite large …

Total answers: 3

How to remove this annoying message?

How to remove this annoying message? Simple question, I run this command ss -tulpnoea|grep -i water|grep -v 127 Failed to find cgroup2 mount Failed to find cgroup2 mount Failed to find cgroup2 mount Failed to find cgroup2 mount Failed to find cgroup2 mount Failed to find cgroup2 mount Failed to find cgroup2 mount Failed to …

Total answers: 1

Redirect stderr doesn't show python input

Redirect stderr doesn't show python input I am running the following command on the terminal: python -c "input(‘Message’)" 2> log but the Message doesn’t appear on the screen. Any ideas why this happens? Asked By: ado sar || Source In these circumstances, and in spite of what the documentation says, Python writes the prompt to …

Total answers: 1

mysqldump failing when launched from script

mysqldump failing when launched from script Running next command in terminal is working fine like expected. /var/www$ sudo mysqldump –defaults-extra-file=/mnt/./.sql/mysqldump.cnf –databases site3 –hex-blob | sudo tee /mnt/site3/20230404_site3.sql running the same command from within script -rwx—— 1 root root 1686 apr 4 22:23 BackupDrupal.sh /var/www$ sudo ./BackupDrupal.sh site3 is ending with next message: /*!40000 ALTER TABLE …

Total answers: 2

Run a scheduled command on open terminal

Run a scheduled command on open terminal A task/script scheduled with cron or at (AFAIK) can not run inside a specific terminal: it can only print the output (through redirection) of a task/script to a specific terminal. Instead, I would like to schedule a command which should run in an already open terminal, as if …

Total answers: 1

Why is appending different streams to a file safe?

Why is appending different streams to a file safe? It’s well known that redirecting standard output and error to the same file with cmd >out_err.txt 2>out_err.txt can lead to loss of data, as per the example below: work:/tmp$ touch file.txt work:/tmp$ ls another_file.txt ls: cannot access ‘another_file.txt’: No such file or directory The above is …

Total answers: 2

Show application list with description, ommitting "nothing appropriate"

Show application list with description, ommitting "nothing appropriate" I’ve been working on a script with a variety of functions. I’m trying to add a function that show’s the output of the whatis command for all applications in the "/usr/share/applications" folder, without showing lines that say "nothing appropriate". My current command attempt is: whatis $(ls /usr/share/applications …

Total answers: 2