Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDzPv-00055M-1x for pgsql-general@arkaria.postgresql.org; Mon, 22 Feb 2021 00:49:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lDzPt-0001N0-Ud for pgsql-general@arkaria.postgresql.org; Mon, 22 Feb 2021 00:49:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDzPt-0001Mt-Kr for pgsql-general@lists.postgresql.org; Mon, 22 Feb 2021 00:49:37 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lDzPr-0004Kk-Kx for pgsql-general@lists.postgresql.org; Mon, 22 Feb 2021 00:49:36 +0000 Received: by mail-io1-xd2a.google.com with SMTP id d15so3310340ioe.4 for ; Sun, 21 Feb 2021 16:49:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=exAaHDC0VYHpLPLAk4AOM9Bq/Rug3Wdpct8ks+9jxjc=; b=A8DbMUIxSjKMxPoKaOxCq3zDtxn48UFInMYr11xNsxjTMHuRpebnxKqZb0Vsq2NXEK 1bfpZGv8x5TDH4jpsKndyfFvI+vr1OJu4KTz/jm0gh5NRGCKuMFJQheL6DG3FXSGVsRl F5hL/WVRPS5+ROPmLkgWcpkaWRp30zAzKj8RBdJEdUNX7xcGYARBWSsfkJ7fQbnkMgY5 AzmQmNDtsEYKmYjUqWMBMP/e/GB23nWOvVJhmfS59fQQwiJMGpbI8HEWdk4LNzb94AVd ZnMirUp6tjm0HsO69cFe+G0EJeNn/aZHPJY0LDN7pESrwdUJOBld+MlyhuNc4RjPFM6P cR5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=exAaHDC0VYHpLPLAk4AOM9Bq/Rug3Wdpct8ks+9jxjc=; b=hAeHDO1kbmPORhPI/fWSojfLkYiG55jnhGkZTQy9eREYmu8v69PQUIAH+xcrzEYvl6 o9Mq4mf784ZzH3nQJrY34gFf68MwoH/HMAzYZMQIukG0gteH7sqIQGQQJuFG+w2W1OuS 6LdcCyhhflE4azaL9Wa2Quyrvw/bYe3AxKoHw9EtX9QYI21ctDGCOvWb1ocaXL0f2WVd 1Cf7ATAfiNfg1aS4UYspORkoHc/KV3Q8bXoyFMgSsVGeAQ/l3C2F7x9j+w55jY9rYA1R Em/rZJKWVkdvkCefyRpvtOgeeCNF7SCGbj+6pAT2/e2gqU9WgSdSNaYTT4dGD6WLz1+f MWKw== X-Gm-Message-State: AOAM532X/F80eNJqH2kKTig9s5eyaezpAzV1H7BhBjPa/94qha2jd6aC i+/XjtIlXQtIjSZjIyqjPmU6HeQazBI= X-Google-Smtp-Source: ABdhPJxZVyHO+FaF68tdES7Vv3eGcCC3CX8uxenICi2GRAmHbN3OAiwgUnHCqQ1uJnu1VWWMdKTONQ== X-Received: by 2002:a6b:8f97:: with SMTP id r145mr13349837iod.133.1613954974522; Sun, 21 Feb 2021 16:49:34 -0800 (PST) Received: from ?IPv6:2601:681:5500:dde0:299d:7cec:87c:8f52? ([2601:681:5500:dde0:299d:7cec:87c:8f52]) by smtp.gmail.com with ESMTPSA id n7sm10706598ile.12.2021.02.21.16.49.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Feb 2021 16:49:34 -0800 (PST) Subject: Re: Script checking to see what database it's connected to To: pgsql-general@lists.postgresql.org References: <0437e8e0-5686-9a10-b204-0b9df86e27ef@gmail.com> <747b62a4-128c-093e-e212-252c34cea42c@gmail.com> From: Rob Sargent Message-ID: <5e45b234-9390-e394-dc31-4dc3f7dbffdc@gmail.com> Date: Sun, 21 Feb 2021 17:49:33 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >> >> Take it up a notch?  Write a script which takes the dbname and the >> script name: >> >> /pcode/ >> >> #!/bin/bash -e >> if [[ $# -ne 2 ]]; then echo "missing arg(s)"; exit 2; fi >> dbn=$1; shift; >> sql=$1; shift; >> psql --dbname $dbn --file $sql >> >> /pcode/ > > I thought of that, yet so earnestly want avoid Yet Another Tiny Script. > Isn't it a toss-up with putting the check in every sql script? Or make it /really/ fancy: use proper arg parsing; check for existence of the sql script; add a usage function; split stdout/stderr... No end of fun.