How to execute MS SQL PLSQL script multiple time from LINUX Box - sql

I've PL SQL Block ; which needs to be executed multiple times in a day.
This Block updates data in Microsoft SQL Server.
Is there any way; I can connect MS SQL Database from Linux box and schedule query execution multiple times in a day?

Write a script and then use crontab to schedule the task to run as often as you would like.
To Edit: crontab -e
While in crontab it works just like vi. So to edit, press i. To stop editing press the Esc. To save and quit type :wq.
To view: crontab -l
for questions: man crontab
crontab example:54 14 * * * myJob This will run "myJob" at 2:54pm, daily.
You could also use something like this to help you make the schedule for crontab http://crontab-generator.org/

Related

How can I most simply automate an Oracle query in windows?

I need to run the same damn Oracle query daily (and export the output, which I can do from the sql file itself). I'd like to automate using Windows Task Scheduler but it only opens the script, and it doesn't run it.
Is this feasible or is there an easier way?
Your description isn't very descriptive (we don't know how exactly you did that), but - here's a suggestion:
create a .bat script (let's call it a.bat) which will call your .sql (let's call it a.sql) script. Only one line in it:
sqlplus scott/tiger#orcl #a.sql
a.sql is ... well, what it is, for example
prompt Number of rows in EMP table
select count(*) from emp;
Create a job in Task Scheduler which will start a program (a.bat).
I've just tried it (using that simple example I posted above) and got the result (saying that there are 14 rows in the table), so I hope you'll get it as well.

Automatically updating data from an API to an SQL database?

I have data coming from an API in JSON format which I then run a few functions/transformations in python and then insert the data in to an SQL database through pandas & SQLalchemy.
Now, how do I automatically do this at the end of every day, without having to open up the script and run it manually?
You can use crontab on a server (or your Linux/Mac laptop but it will not run the script if its turned off of course).
You can run crontab -e to edit the crontab file. Add something like the following to run your script everyday at 11 PM:
0 23 * * * ~/myscript.py
crontab guru is a useful resource to try different schedule expressions.

How to use sqlcmd to execute many queries in one table?

I have many SQL scripts; I want to execute them in one table using sqlcmd.
I have created a new database and a new table. How can I read several files from my PC and execute them in one table?
Refer this
1.Click Start, point to All Programs, point to Accessories, and then click Notepad.
2.Copy and paste the following Transact-SQL code into Notepad:
USE <DBName>;
GO
select *from table1
select *from table2
select *from table3
select *from table4
select *from table5
--give all your select query here
GO
Save the file as myScript.sql in the C drive.
3.To run the script file
4.Open a command prompt window.
In the Command Prompt window, type: sqlcmd -S myServer\instanceName -i C:\myScript.sql
Press ENTER.
The result of the sql file is written to the command prompt window.
To save this output to a text file
5.Open a command prompt window.
In the Command Prompt window, type: sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt
Press ENTER.
No output is returned in the Command Prompt window. Instead, the output is sent to the EmpAdds.txt file. You can verify this output by opening the EmpAdds.txt file.
You can easily do this with SQLS*Plus from the command line:
SQLS>#script001
SQLS>#script002
SQLS>#script003
SQLS>#script004
You can also create a master script that contains calls to all these scripts.
FYI:
I wrote SQLSPlus in my free time, this is a cool tool for SQL Server that is helpful to tons of DBAs, especially with the Oracle background - it is like Oracle SQLPlus but for SQL Server.
Tool is great for DBAs (I shared some of the received feedback on the web site), much better than SQL Server sqlcmd and also great for the command line reporting and automation. There is a 100% free version for the business users.
Already got few great clients around the world using it in production. One client, for example, moved lots of Oracle SQL*Plus reports to SQL Server in just a couple of hours.
It is on https://www.sqlsplus.com

Schedule Oracle Reports and export to XML

I have a report that I need to run everyday # 00:00 and export all the information from the table to a specific location with a specific name.
Example:
select * from my_table
where date between SYSTIMESTAMP -2 and SYSTIMESTAMP -1
and to export this to file date.xml.
Is this possible from Oracle SQL Developer or do I need other tools?
No Oracle version so I assume 10 or 11.
To schedule your process you just have to create a job and schedule it. The job has to run your script (which can be a function or a stored procedure).
Here is the documentation:
http://docs.oracle.com/cd/B28359_01/server.111/b28310/scheduse.htm#i1033533
To write to a file you can use the spool command in SQL. Here you can find the documentation: http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12043.htm
It's really simple to use.
spool #path/nomefile
la tua query
spool off
Obviously, the machine from which you run the script must have write permissions on the machine where you're going to write the file (I say this because I often forget to check out).
To create an XML is slightly more complex and a little long to explain here but there is a nice post on the community of Oracle that explains it and makes a simple and practical example: https://community.oracle.com/thread/714758?start=0&tstart=0
If you do not want to use a job in Oracle you can write a .Sql file with the connection commands, the spool command and your query and schedule it on the server machine on which you intend to set as a simple command sqlplus.

Schedule a cronjob on ssh with command line

I am using the amazonaws es3 server.I want to schedule my cron with command line.
I am using the this command for scheduling the cron job
at -f shellscript.sh -v 18:30
but it will schedule for only one time i want to configure manually like once a day or every five minutes .
Please help with command which command i have to used
Thnaks,
As #The.Anti.9 noted, this kind of question fits in Serverfault.
To answer your question, crontab is a little more powerful than 'at' and gives you more flexibility as you can run the job repeatedly for instance daily, weekly, monthly.
For instance for your example, if you need to run the script every day at 18:30 you'd do this,
$ crontab -e
then add the following
30 18 * * * /path/to/your/script.sh
save and you are done.
Note: 30 18 indicates time 18:30, and *s indicate that it should run every day of every month) If you need to run it on a particular day of the month just check it out on the man page of crontab.
Doesn't crontab -e work?
and to generate crontab code http://www.openjs.com/scripts/jslibrary/demos/crontab.php should help.
You can use the command crontab -e to edit your cron planned execution. A good explanation on how to set the time can be found on the Ubuntu forum