<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vi editor &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/vi-editor/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 21 Jan 2019 07:18:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>PostgreSQL: Bash Shell Script to execute psql command in UNIX / LINUX</title>
		<link>https://www.dbrnd.com/2019/03/postgresql-bash-shell-script-to-execute-psql-command-in-unix-linux/</link>
					<comments>https://www.dbrnd.com/2019/03/postgresql-bash-shell-script-to-execute-psql-command-in-unix-linux/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 04 Mar 2019 16:16:25 +0000</pubDate>
				<category><![CDATA[Bash Shell Script]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Bash shell script]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<category><![CDATA[vi editor]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4374</guid>

					<description><![CDATA[As per the en.wikibooks.org: Bash is a &#8220;Unix shell&#8221;: a command-line interface for interacting with the operating system. It has the ability to run an entire script of commands, known as a &#8220;Bash shell script&#8221;. I recently started to create UNIX / LINUX Bash Shell script for enhancing my PostgreSQL DBA Work. You can create [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&#038;title=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" data-a2a-url="https://www.dbrnd.com/2019/03/postgresql-bash-shell-script-to-execute-psql-command-in-unix-linux/" data-a2a-title="PostgreSQL: Bash Shell Script to execute psql command in UNIX / LINUX"></a></p><p>As per the en.wikibooks.org:</p>
<blockquote><p>Bash is a &#8220;Unix shell&#8221;: a command-line interface for interacting with the operating system. It has the ability to run an entire script of commands, known as a &#8220;Bash shell script&#8221;.</p></blockquote>
<p>I recently started to create UNIX / LINUX Bash Shell script for enhancing my PostgreSQL DBA Work. You can create a Bash shell script and can connect PostgreSQL using psql. </p>
<p>In this post, I am sharing a sample bash shell script to execute psql commands. </p>
<p><strong>Open a new file in vi editor:</strong></p>
<pre class="crayon-plain-tag">[root@dbrnd anvesh]$ vi helloworld.bash</pre> </p>
<p><strong>Press [i] key to get an insert prompt:</strong></p>
<p><strong>Copy below sample Bash Shell Script and Paste into vi editor:</strong></p>
<pre class="crayon-plain-tag">#!/bin/bash

###################################################
# First Bash Shell script to execute psql command 
###################################################

#Set the value of variable
database="database_name"

#Execute few psql commands: 
#Note: you can also add -h hostname -U username in the below commands. 

psql -d $database -c "CREATE TABLE public.tbl_students(rno integer, name character varying)"
psql -d $database -c "INSERT INTO public.tbl_students VALUES (1,'Anvesh'),(2,'Neevan'),(3,'Roy'),(4,'Martin'),(5,'Jenny')"
psql -d $database -c "SELECT *FROM public.tbl_students"

#Assign table count to variable
TableCount=$(psql -d $database -t -c "select count(1) from public.tbl_students")

#Print the value of variable
echo "Total table records count....:"$TableCount</pre> </p>
<p><strong>Press [Esc] key to get a command prompt and execute below command:</strong><br />
To save and exit vi editor.</p>
<pre class="crayon-plain-tag">:wq</pre> </p>
<p><strong>Give permission to the file:</strong></p>
<pre class="crayon-plain-tag">[root@dbrnd anvesh]$ chmod +x helloworld.bash</pre> </p>
<p><strong>Execute this file:</strong></p>
<pre class="crayon-plain-tag">[root@dbrnd anvesh]$ ./helloworld.bash</pre> </p>
<p><strong>You can find below result:</strong></p>
<pre class="crayon-plain-tag">rno |  name
-----+--------
   1 | Anvesh
   5 | Jenny
   2 | Neevan
   3 | Roy
   4 | Martin
(5 rows)

Total table records count....: 5</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/03/postgresql-bash-shell-script-to-execute-psql-command-in-unix-linux/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
