When I run this script:

# internet-status.sh
# ==================

now=$(date +%F)
cmd_output=$(nc -dzvw1 443 2>&1)
logfile_string=$("[$now] $cmd_output")
$logfile_string >> "$logfile"

it returns:

/home/xxxx/internet.log: Permission denied

I've run chmod u+x on internet-status.sh

The permissions are:

-rw-rw-rw- internet.log and -rwxrw-r-- internet-status.sh


$(...) is a command substitution.

Whereas date +%F and nc -dzvw1 443 2>&1 are commands, "[$now] $cmd_output" and "$HOME/internet.log" are just strings - and should be assigned as such:

logfile_string="[$now] $cmd_output"

You then presumably want to echo the string to the file:

echo "$logfile_string" >> "$logfile"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.