Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have here the batch file in windows, I want to apply the same to linux. May I ask your help to run it in linux. Below is the batch file for windows:

@echo off

TITLE Upload Masterlist

set /p answer=Do you want continue? [Y/N]:

if %answer%==Y goto G
if %answer%==y goto G
if %answer%==N goto EndoF
if %answer%==n goto EndoF

:EndoF
goto:eof

:G
cls
set MYSQL_HOME=mysql>C:\xampp\mysql\bin\mysql.exe
set database_name=ppn
set user_name=root
set password=
set sql_file=C:\LEGAL_BACKUP\Masterlist.sql

%MYSQL_HOME% -u %user_name% -p %password% -D %database_name% < %sql_file%


echo.
echo. Uploading Masterlist is successfully done..............!
echo.&pause&goto:eof

Thanks in advance,

Jet

share|improve this question

2 Answers 2

It looks like your batch file is designed to back up a MySQL database on the local machine. While it is possible to translate the .bat commands into equivalent bash commands, the names of the executables, the directories, etc. would all be different.

Instead, you might want to try MySQL-Maint, an open-source Linux-friendly bash script designed to do exactly what you are doing.

share|improve this answer
    
It's not a backup, it's an import (has <instead of >). The SQL file is loaded into the specified database. –  onik Jan 25 '13 at 8:37
    
Ah my mistake. I believe MySQL-Maint can handle that too, but it may be overkill. –  Travis G. Jan 25 '13 at 8:42

Try this:

#!/bin/bash

read -p "Do you want to continue? " -n 1
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
    exit 1
fi

MYSQL_BIN=/usr/bin/mysql
DB_NAME=ppn
DB_USER=root
DB_PASS=pass
SQL_FILE=/home/user/sqlfile.sql

$MYSQL_BIN -u$DB_USER -p$DB_PASS $DB_NAME < $SQL_FILE
echo "Uploading Masterlist is successfully done..............!"

unset MYSQL_BIN
unset DB_NAME
unset DB_USER
unset DB_PASS
unset SQL_FILE
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.