Rather: not found

Hey
I have a weird "problem" here It's more out of curiosity, my script is working fine, but giving me a "pidt.sh: 7: Rather: not found" error...

#!/bin/sh 
log="log/`date +%F_pidt.log`" 
echo "---n`date`n---n" >> $log 
for i in `cat pidt.conf` 
do 
        [ `pidof $i | wc -l` -gt 0 ] || $( /etc/init.d/$i start && echo "$i restarted..." >> $log) 
done 
echo "nn" >> $log 
exit

But ... why?^^

Look better in here:

[ `pidof $i | wc -l` -gt 0 ] || $( /etc/init.d/$i start && echo "$i restarted..." >> $log)

with the dollar sign and parentheses, you are posting the output of your command inside ().
So if your command

/etc/init.d/$i start && echo "$i restarted..." >> $log

outputs something like this:

Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service dmesg start

shell is trying to execute this; and can't find "Rather" command.

What you probably wanted was

[ `pidof $i | wc -l` -gt 0 ] || { etc/init.d/$i start && echo "$i restarted..." >> $log; }

or

[ `pidof $i | wc -l` -gt 0 ] || (etc/init.d/$i start && echo "$i restarted..." >> $log)

The second construct will run the command in subshell.

1 Like

change your line to

[ `pidof $i | sed '/^$/d'|wc -l` -gt 0 ] && echo "$i service already running..." >> $log || (/etc/init.d/$i start ; echo "$i restarted..." )>> $log
1 Like

Oh thanks a lot
I'm always forgetting that the output is treated as command >_>
Thanks!

And thanks for the improvement :smiley: