Create Infinite Looping Repeating File Cat in Linux/Bash

create infinite looping repeating file cat in linux/bash

Process substitution provides a mechanism by which bash can generate a temporary, readable filename connected to an arbitrary chunk of bash code for you:

./my_program -input <(while cat file_to_repeat; do :; done)

This will create a /dev/fd/NN-style name on operating systems that support it, or a named pipe otherwise.

How do I concatenate file contents into a single file in bash?

Converting my comment to an answer. You can use following find + xargs pipeline command:

cd /parent/dir

find home -name "*.orc" -print0 | xargs -0 cat > test.orc

Shell infinite loop to execute at specific time

Check the time in the loop, and then sleep for a minute if it's not the time you want.

while :
do
if [ $(date '+%H%M') = '0600' ]
then /home/sas_api_emailer.sh |& tee first_sas_api
fi
sleep 60
done

Syntax for a single-line while loop in Bash

while true; do foo; sleep 2; done

By the way, if you type it as a multiline (as you are showing) at the command prompt and then call the history with arrow up, you will get it on a single line, correctly punctuated.

$ while true
> do
> echo "hello"
> sleep 2
> done
hello
hello
hello
^C
$ <arrow up> while true; do echo "hello"; sleep 2; done

While loop stops reading after the first line in Bash

The problem is that do_work.sh runs ssh commands and by default ssh reads from stdin which is your input file. As a result, you only see the first line processed, because the command consumes the rest of the file and your while loop terminates.

This happens not just for ssh, but for any command that reads stdin, including mplayer, ffmpeg, HandBrakeCLI, httpie, brew install, and more.

To prevent this, pass the -n option to your ssh command to make it read from /dev/null instead of stdin. Other commands have similar flags, or you can universally use < /dev/null.



Related Topics



Leave a reply



Submit