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
Base Address at Which The Linux Kernel Is Loaded
How to Install Docker 1.9+ in Centos 6.5
Linux Kernel Aio, Open System Call
Rtnetlink Answers: No Such File or Directory
Can Tmux Save Commands to a File, Like .Bash_History
Reading from a File in Assembly
How to Setup Cron Job on Amazon Linux Ami
Replace Forward Slash with Double Backslash Enclosed in Double Quotes
How to Write Kernel Space Memory (Physical Address) to a File Using O_Direct
Check If a Git Branch Is Ahead of Another Using a Script
Setup Sftp to Use Public-Key Authentication
Where Is Default Installation Directory for Mongodb
Automatically Adjusting Process Priorities Under Linux
How to Avoid Grub Errors After Running Apt-Get Upgrade - Ubuntu
How to Get Groupname When I Have The Groupid
Two Processes Write to One File, Prevent Mixing The Output