# executing SQL query using unix shell script

**URL:** <https://community.unix.com/t/executing-sql-query-using-unix-shell-script/255118>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [December 4, 2009, 1:04am UTC](https://community.unix.com/t/executing-sql-query-using-unix-shell-script/255118 "2009-12-04T01:04:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathanvaithi](https://community.unix.com/letter_avatar/nathanvaithi/32/5_5575768a8748004e209b776fc1b2916d.png) [@nathanvaithi](https://community.unix.com/u/nathanvaithi)\
**Post date:** [December 4, 2009, 1:04am UTC](https://community.unix.com/t/executing-sql-query-using-unix-shell-script/255118/1 "2009-12-04T01:04:34Z")

</div>

I want to perform few post-session success tasks like update a status to 'true' in one of the sql database table, update date values to current system date in one of the configuration table in sql. How do i achieve this in a post session command?syntax with example will be helpful.

---

<div class="post-metadata">

**Author:** ![thegeek](https://community.unix.com/letter_avatar/thegeek/32/5_5575768a8748004e209b776fc1b2916d.png) [@thegeek](https://community.unix.com/u/thegeek)\
**Post date:** [December 4, 2009, 6:44am UTC](https://community.unix.com/t/executing-sql-query-using-unix-shell-script/255118/2 "2009-12-04T06:44:32Z")

</div>

Yep, i dont know how to do this shell script.

But if possible call a PERL script, and use DBI to do the database operations from PERL script, hope this helps.

---

<div class="post-metadata">

**Author:** ![jsmithstl](https://community.unix.com/letter_avatar/jsmithstl/32/5_5575768a8748004e209b776fc1b2916d.png) [@jsmithstl](https://community.unix.com/u/jsmithstl)\
**Post date:** [December 4, 2009, 6:58am UTC](https://community.unix.com/t/executing-sql-query-using-unix-shell-script/255118/3 "2009-12-04T06:58:59Z")

</div>

Here's how I do it in Oracle. I don't know if it will work for you or not, but you can test it.

```nohighlight
sqlplus -s /NOLOG <<EOF
   connect username/password
   select 'blah' from dual;
   exit
EOF

```

If you need to store the returned value:

```nohighlight
MYVAL=$(sqlplus -s /NOLOG <<EOF
   connect username/password
   select 'blah' from dual;
   exit
EOF)

```

---

<div class="post-metadata">

**Author:** ![akshay61286](https://community.unix.com/letter_avatar/akshay61286/32/5_5575768a8748004e209b776fc1b2916d.png) [@akshay61286](https://community.unix.com/u/akshay61286)\
**Post date:** [December 4, 2009, 9:50pm UTC](https://community.unix.com/t/executing-sql-query-using-unix-shell-script/255118/4 "2009-12-04T21:50:27Z")

</div>

> [@jsmithstl](#):
>
> Here's how I do it in Oracle. I don't know if it will work for you or not, but you can test it.
> 
> ```plaintext
> sqlplus -s /NOLOG <<EOF
> connect username/password
> select 'blah' from dual;
> exit
> EOF
> 
> ```
> 
> If you need to store the returned value:
> 
> ```plaintext
> MYVAL=$(sqlplus -s /NOLOG <<EOF
> connect username/password
> select 'blah' from dual;
> exit
> EOF)
> 
> ```

Yup as said by jsmithstl, you need to use the here doc.

for mysql use :  
mysql -u \<user\> -p\<pwd\> -e "\<your query\>"

Cheers
