Easiest Way to Execute a Node Script - mysql

I have an AWS-hosted MySQL database with 900+ records. I've developed a Node script that queries the database for new records, generates MP3 files for each one, uploads those files to S3 storage, and inserts the links into my database.
Right now, I'm having to execute that script manually via command prompt (npm). The script only needs to be run occasionally, so running it manually isn't a problem. But I'm sure there's an easier way than command prompt.
Is there a way to automatically run the script every so often? Or perhaps run it via a desktop shortcut? I'm open to ideas on this...just looking to simplify.
I am very new to Node and all things programming, so please forgive my ignorance here.

In Linux, you could run as a pure Linux shell script. Use a cron job to schedule the script.
Ex :
#!/usr/bin/env node
console.log('Hello world!');
In Windows, if you want to run manually, you could create a bat file and run the bat file to run the script.
Ex :
name : my_node_script.bat
node c:\path\to\file\my_node_script_code.js
If you want to run the bat file periodically, you could use Task Scheduler to schedule the bat file. See this guide of you want more details on scheduling.

Related

running scripts on ssh remotely

I have a python script and a file (both on ssh) to be inserted to a db (mysql) using the python script. My file has 53,000,000 rows to be submitted to the db. This submission takes a very long time. Is there anyway in which I can run the script so that even if I exit ssh the script continues running?
Thanks,
You can use the screen or tmux. Both commands allow you to have detached user session. You can reconnect at any time to this session.
You only need to start screen and run your scripts there. After that you can push ctrl+a and than d and your session will be detached.
To restore your session you need to run screen -a.
Why dont you have it handled in a jenkins pipline, setup a job in jenkins to run the script.

Recording MySQL executions to script file in WIndows?

for my database systems assignment after we create somethings in mySQL we need to record our executions in a script file to print off to show we actually did it.
I know how to create a script file in Linux but I cannot see how to do one in Windows?

How can I automate mysqldump database backups in Windows Server 2012?

I'm trying to get mysqldump to do backups to a .sql file automatically, I have being reading that I need to use cron jobs or Windows Task Scheduler; the problem is that I can't find anything online that shows me how to do it.
To do the backups I'm using cmd with the following commands:
mysqldump --user username --password=123 databtable > backup.sql
This command works perfectly, it does create the .sql file but how do I automate it in such a way that it does the backup every certain time.
Hopefully you can help me and thank you so much!
You should use the schtasks command in Windows.
Command syntax details are available here: https://technet.microsoft.com/en-us/library/cc772785(v=ws.10).aspx
You could also use the Task Scheduler application in Windows if you like GUIs:
Create a new basic task
Set the Trigger (run daily, weekly, etc)
Set the Action. (what program to run) Be sure to
include only the executable in the Program field, and put the
command arguments in the Add Arguments field.
You probably want to set your task to 'Run whether the user is logged on or not'. This is achieved by modifying the task, and adjusting the Security Options on the General Tab of the task.
When troubleshooting your task, use the History tab for info regarding job failures.

Appserv command line batch

I use Java and MySQL with Appserv. I have a database file named "modb.sql" (in a specific directory relative to my program's location), and I frequently need to drop the old database, create a new database (with the same name every time, inside phpMyAdmin) and import the modb.sql file to the new DB.
Is there a way to automate this process and include it with the program or inside a setup file? Instead of doing it manually by me or the user.
I can use another MySQL database manager or C# instead of Java if that would allow the process to be automatic.
You can do all of this from the Windows command line or through a Scheduled Task. I don't have Appserv installed, so I can't give you all of the exact file path locations which may vary based on your installation location. You could technically do it from a Java application as well, but that's a lot of overhead and not really automating it like a schedule task will.
You'll basically be calling the mysql.exe command directly from your schedule task -- or from a batch file.
First, let's create a new SQL file, perhaps called DropAndCreateMoDb.sql. Put your commands to drop (DROP DATABASE ...) and recreate the database here. Of course the exact drop command depends on what you call your database and the create command depends heavily on what structure is created by modb.sql; you'll also create any permissions that you need to here. This automates the part about dropping and recreating.
Write a batch file. You don't really need to do this, you could call MySQL twice from the schedule task, but we're trying to do this the right way. This is untested, and obviously you'll want to substitute the proper paths and MySQL username/password -- I suggest creating a maintenance account for this so your full credentials aren't in the batch file; the usual disclaimers apply about properly securing your account), but perhaps something like:
#ECHO OFF
C:\Program Files\Appserv\MySQL.exe -u foo -p bar < C:\data\DropAndCreateMoDb.sql
C:\Program Files\Appserv\MySQL.exe -u foo -p bar < C:\data\modb.sql
Obviously it doesn't catch any errors and your username and password are in the clear here, but as long as this is on your local development machine for development purposes and you know and understand the risks, it will work.
At this point, you can double-click the .bat file and it should drop and recreate your database. To finish it off and fully automate it, you'll add a scheduled task. Go to the Scheduled Tasks control panel and add a new task. Tell it the path to your new DropAndRecreate.bat or whatever you decide to call it, tell Windows when you want the task to run, and now it's fully automated.
There are lots of variables here that make the specifics of the implementation very dependent on your exact configuration and so on. Make sure you understand what each step actually does instead of just copying and pasting.

Run MySql script as batch file on Windows Server

I have about 3 or so weekly generated .CSV files that are automatically placed in a particular directory on my MySQL box.
What I would like to do is run some sort of automated script that opens the MySQL command line and executes a query to delete all records in the corresponding table and LOAD DATA INFILE from the CSV's.
Being that I'm on Windows I cannot do a chronjob, though I was thinking I could do some sort of batch script and run it as a Scheduled Task.
Any idea how I would go about doing this?
Depending on your MySQL version you could use CREATE EVENT to schedule some database statements, check:
http://dev.mysql.com/doc/refman/5.1/en/create-event.html