0

When I run this script:

#!/bin/bash
# internet-status.sh
# ==================

now=$(date +%F)
cmd_output=$(nc -dzvw1 8.8.8.8 443 2>&1)
logfile_string=$("[$now] $cmd_output")
logfile=$("$HOME/internet.log")
$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

2

$(...) is a command substitution.

Whereas date +%F and nc -dzvw1 8.8.8.8 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"
logfile="$HOME/internet.log"

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.