There is a script in bash, it runs from itself, but for some reason, then the line variable is written empty.

container="name" hostname=$(hostname) space="$(docker exec -it $container df -h | awk '{printf $1 ":" $4 "\n"}' )" arr=() while read -r line; do arr+=("${hostname}:${container}:${line}") done <<< "$space" printf "%s\n" "${arr[@]}" >> freediskspace 2>&1 

cron: * / 1 * * * * root cd / opt / scripts / && / bin / bash freedisk.sh

2 answers 2

To begin, the file must be made executable:

 chmod +x /opt/scripts/freedisk.sh 

then it would be good to indicate how to execute the script using:

 #!/bin/bash 

this is written at the very beginning of the script a couple more edits and the result:

 #!/bin/bash container="name" hostname=$(hostname) space="$(docker exec -it $container df -h | awk '{printf $1 ":" $4 "\n"}' )" arr=() while read line; do arr+=("${hostname}:${container}:${line}") done < $space printf "%s\n" "${arr[@]}" >> freediskspace 2>&1 
  • "from itself it is executed" - this means that the rights to perform are granted. "#! / bin / bash" is all spelled out, here brought a piece of code - element

it's decided! Made in krone redirection of an error output in a file. The file was "tty is not a tty with docker exec". To solve this, remove -t in when you start the docker, that is, you get the following docker exec -i ....