0

Hey I have the following problem:

FILE=/etc/squid3/conf.d/$CUSTOMER.conf

Everytime i'm doing that:

grep -o $replaced_ip $FILE

grep: /etc/squid3/conf.d/.conf: Data not found

I've startet the script together with the $CUSTOMER variable, so it is not empty. Guess I'm having a syntax error? Thanks for any advice.

while getopts :c:s:d:hI:p:r:l:fa: FLAG; do
  case $FLAG in


        s)
                SOURCE=$OPTARG
                ;;

        d)
                DESTINATION=$OPTARG
                ;;

        I)
                ISSUE=$OPTARG
                ;;

        c)
                CUSTOMER=$OPTARG
                test -e /etc/squid3/conf.d/$CUSTOMER.conf
                customer_available=$?
                ;;
Cyrus
  • 84,225
  • 14
  • 89
  • 153
tso
  • 187
  • 4
  • 13
  • 3
    please post the customer variable initialization as well – Lino Aug 15 '16 at 07:05
  • 3
    Customer is quite obviously empty... – 123 Aug 15 '16 at 07:23
  • $CUSTOMER is inside getopts – tso Aug 15 '16 at 07:42
  • @tso post your getops line – Farhadix Aug 15 '16 at 07:45
  • while getopts :c:s:d:hI:p:r:l:fa: FLAG; do case $FLAG in s) SOURCE=$OPTARG ;; d) DESTINATION=$OPTARG ;; I) ISSUE=$OPTARG ;; c) CUSTOMER=$OPTARG test -e /etc/squid3/conf.d/$CUSTOMER.conf customer_available=$? ;; – tso Aug 15 '16 at 07:54
  • put it in the description – tso Aug 15 '16 at 07:55
  • And how do you call the script? – 123 Aug 15 '16 at 07:56
  • Have you tried removing the first ':' and seeing if getopts reports an error? What are the args that getopts parses (i.e. can you provide a command-line example)? – Karl Nicoll Aug 15 '16 at 08:33
  • The error message *Data not found* is odd. I have never seen it with grep. Which grep are you using? As for the error message: Can you reproduce it from the command line? To do this, turn on `set -x` just before the grep statement in your script, so that you see what is actually executed (you can turn it off, `set +x`, afterwards). – user1934428 Aug 15 '16 at 09:42
  • Your `while/case` are missing `esac/done`: clease create a complete example. AFAIK you might have an option `f) echo "f: Todo"` without `;;` where your CUSTOMER os changed again. – Walter A Aug 15 '16 at 16:26

0 Answers0