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 1lDzdg-0005YR-6n for pgsql-general@arkaria.postgresql.org; Mon, 22 Feb 2021 01:03:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lDzdf-0004K7-4D for pgsql-general@arkaria.postgresql.org; Mon, 22 Feb 2021 01:03:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDzde-0004K0-Sp for pgsql-general@lists.postgresql.org; Mon, 22 Feb 2021 01:03:50 +0000 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lDzdY-0003bs-JW for pgsql-general@lists.postgresql.org; Mon, 22 Feb 2021 01:03:50 +0000 Received: by mail-oo1-xc2a.google.com with SMTP id y21so2564358oou.13 for ; Sun, 21 Feb 2021 17:03:44 -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-transfer-encoding:content-language; bh=mEokFBvw+417F/znHipEvfgPLahM7okyKr5u55ScdEA=; b=nhyIA/kejjA9eoBAgfV0I13ULlZqu3GimdO/zqj4BPlish240TB3hYOey07WEChICh IjhoVexyeeRSvjWk8y2DdqjGgH88AQZPecbb5KOz1802FOQCQzSu7sBFpxiS3Cv7Gr/D dteG0uL9nBklFIXWLYsqpV8DEoidbQbHxE4RFeRDQo9Hm748hCYf5Wkgt8dWwTW9nYil Aj3SSiZIYcwDnzbg3SvNHZF3F0T+PJHVzoFjXB+e64nL0sdOvOUbzGoIVB6zAVRAakT9 K7whcZ7SQGZNqihCRfdrOVKvPZxmQ+Nslcp04mkbghIKwhvqE/EvuykXT/Z06b45qenD Dd9w== 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-transfer-encoding :content-language; bh=mEokFBvw+417F/znHipEvfgPLahM7okyKr5u55ScdEA=; b=OpKCspUARKfboctv6zF11Bywbov2Au7oqXAstQigIWTFHl754M4pg3GIvyDKg8kTxt 38BBbVkyfOHCl/Eppp6nyqGcJb2o+cAUyLFH9UbO6WaEhVtx5xrmq9fn+QWyTS8a5mxg kcqE0Y9N+3Sh/Q+hGzJywyCMhIness6p8zh+Ct3rcDq3gn+4/G/4gRrKrVw9odfMmstC VAuMFl6TmCMqeQUYH4FausaQbXn9AF62t6s8h/msP+oMTeZmko66nuoVjS9/0SZqrwK7 7Tw8+yfyVxNsqPZydsiGcA/p26aXniwv6q0VWY+l4Y4Ma9ndBzUkVbvAk8uXzPffmfS/ 98eA== X-Gm-Message-State: AOAM530ncHvYLA3cl5Xj17ROIPLgaaIo3flBIPW0drYyXo12WhIf2Yrf RS7eDo37SbPvdKJM48/7uEeE/Pe6++0UBg== X-Google-Smtp-Source: ABdhPJx3XUWSHCjOroukXAUPeRbn3rhTtEwvzWIiTbAfQAtV89UdIORs8z0sZ+n4ViDYa3Kxx5rdvQ== X-Received: by 2002:a4a:424c:: with SMTP id i12mr14748158ooj.85.1613955822452; Sun, 21 Feb 2021 17:03:42 -0800 (PST) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id h11sm3283391ooj.36.2021.02.21.17.03.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Feb 2021 17:03:42 -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> <5e45b234-9390-e394-dc31-4dc3f7dbffdc@gmail.com> From: Ron Message-ID: <3fb4572b-bd20-5000-38eb-51429c0e3d7a@gmail.com> Date: Sun, 21 Feb 2021 19:03:41 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <5e45b234-9390-e394-dc31-4dc3f7dbffdc@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/21/21 6:49 PM, Rob Sargent wrote: > > >>> >>> 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? I was hoping to "\include" that at the top of each script, since doing that once is easier than remembering to use the script each time. > 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. -- Angular momentum makes the world go 'round.