Using High Sierra I have this set as a cronjob to run once a day.
I've been struggling to work out how to get grep to find the string in the output. Am fairly new to bash scripting.
Any advice on where I went wrong, and examples are appreciated!
#!/bin/bash
printf '\e[2t'
check=$(softwareupdate -l)
sleep 5
echo $check
if [ fgrep "No new software" <<< $check ]
then
say "Peter, You are up to date"
else
say "Peter, you have updates"
fi
Best Answer
softwareupdate
printsNo new software available.
onstderr
, not onstdout
, so it will never get assigned tocheck
. The quick fix is to runThis will redirect stderr (file descriptor 2) to stdout (file descriptor 1).
Also your
if
statement is wrong, the[
is a command, not just syntax. So you can simply runfor this.
But if you don't need the value of
$check
later on you can put all this in one line and just run