I want to create a file every 10 minutes, after the file has been created it will be overwritten with a new name by another programme so a new one should be created by the script below:
#!/bin/bash
echo
while true
do
cat >> trn
echo creating trn
sleep 600
done
when I run this, it creates the first file, doesn't echo the statement then stays in a loop without creating any more files.
Do not use cat >> trn
for that. It is actually blocking execution of your script (awaiting user input)!
You can use instead (for instance)
touch trn
or >> trn
(will create 'trn' file with empty content, only if doesn't already exist)echo > trn
(will create / overwrite 'trn' file with one newline character content)echo -n > trn
or printf ''
(more portable) or simply > trn
(will create / overwrite 'trn' file with empty content)thanks to @CharlesDuffy for his enlightning comments. Info here on better portability of printf ''
over echo -n
.
If your system supports watch
command, then there is this much simpler option that replaces your whole script (credits to @Qback in comments) :
watch -n 600 touch trn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With