Help to rewrite scritp Bash into a batch


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help to rewrite scritp Bash into a batch
# 1  
Old 10-19-2012
Help to rewrite scritp Bash into a batch

Hello,

My Bash script is working but i dont know batch programing, anyone can help me?
I dont want use programs to do this task, i will use in many computers...

Bash:

Quote:
#!/bin/bash

# Verifica se o caminho onde sera gravado o backup foi passado.
# Caso negativo pega um diretorio padrao (/tmp/backup)
if [ $1 ];
then
BACKUP_PATH=$1
else
BACKUP_PATH=/tmp/backup
fi

# Nome do banco
DATABASE=SIRALIMS

# Verifica se o diretorio de backup exite, caso negativo cria um novo
if test ! -d $BACKUP_PATH ; then mkdir -p $BACKUP_PATH; fi

echo "INICIANDO BACKUP NO DIRETORIO ${BACKUP_PATH}..."
echo

## DUMP
echo "CRIANDO DUMP DA BASE DE DADOS..."
echo
ARQUIVO=${BACKUP_PATH}/backup-`date +%d%m%Y-%H%M%S`.dump
/data/bin/pg_dump -Fc $DATABASE -f $ARQUIVO

## VACUUM
echo "EXECUTANDO VACUUM..."
echo
ARQUIVO=/tmp/vacuum-`date +%d%m%Y-%H%M%S`.log
/data/bin/vacuumdb -d $DATABASE -z -v > $ARQUIVO 2>&1

cd $BACKUP_PATH
echo "COMPACTANDO ARQUIVO DUMP..."
echo
BACKUP_FILE=backup-`date +%d%m%Y-%H%M%S`.zip
zip -9 $BACKUP_FILE *

echo "ENVIANDO ARQUIVO PARA SERVIDOR FTP..."
ftp -in << EOF
open 127.0.0.1
user user password
cd ftp
hash
bina
mput ${BACKUP_FILE}
bye
EOF

echo "LIMPANDO ARQUIVOS TEMPORARIOS"
cd /
rm -Rf $BACKUP_PATH
My work until now... BATCH:

Quote:
@ECHO OFF
Rem -- Verifica se o caminho onde sera gravado o backup foi passado.
Rem -- Caso negativo pega um diretorio padrao (/tmp/backup)
if %~1
(
BACKUP_PATH=%~1 )
else
(
BACKUP_PATH=/tmp/backup )

Rem Nome do banco
DATABASE=SIRALIMS

Rem Verifica se o diretorio de backup exite, caso negativo cria um novo
if NOT EXIST %BACKUP_PATH% GOTO mkdir %BACKUP_PATH%

echo = INICIANDO BACKUP NO DIRETORIO %% %BACKUP_PATH% %%...
echo.


rem DUMP
echo = CRIANDO DUMP DA BASE DE DADOS...
echo.

ARQUIVO= %BACKUP_PATH%%%/backup- %date%%%.dump
/bin/pg_dump -Fc %DATABASE% -f %ARQUIVO%

rem VACUUM
echo = "EXECUTANDO VACUUM..."
echo.

ARQUIVO=/tmp/vacuum- %date%%%.log
/bin/vacuumdb -d %DATABASE% -z -v > %ARQUIVO% 2>%~1

cd %BACKUP_PATH%
echo = "COMPACTANDO ARQUIVO DUMP..."
echo.

BACKUP_FILE=backup- %date%%%.zip
zip -9 %BACKUP_FILE% *

echo = "ENVIANDO ARQUIVO PARA SERVIDOR FTP..."
echo.
ftp -in << EOF
open 127.0.0.1
user user password
cd ftp
hash
bina
mput %BACKUP_FILE%
bye
EOF

echo = LIMPANDO ARQUIVOS TEMPORARIOS
cd /
rm -Rf %BACKUP_PATH%
Thanks for help.
# 2  
Old 10-19-2012
Windows CMD is very lacking in syntax and commands. There's no equivalent for here-documents for example, and a lot of the commands you're using will be missing.

I might suggest using busybox for windows instead of rewriting everything from scratch. It's a single executable that packs in a bourne shell interpreter and dozens of different utilities in one. You can busybox sh myscriptname.sh and it'll run it...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Windows Batch to Bash

This line is called in a windows batch file and I need to call the same 3 jars with Parms in a bash script. cd "D:\ACDRIP\JARS" java -cp ".\RIPError.jar;.\RIP31.jar;.\RIP31msg_en_US.jar" ResubmitErrors -Ahost -P185050 pause Any ideas how to do this in Bash? (3 Replies)
Discussion started by: xgringo
3 Replies

2. UNIX for Beginners Questions & Answers

Using BATCH to call a BASH script on CygWin

I am trying to use a batch file to automatically execute a bash script with no luck this far. The batch script looks like this: C:\Cygwin64\bin\bash test.sh I have also tried this: C:\Cygwin64\bin\bash "C:\Cygwin64\bin\test.sh" Needless to say that the windows box has Cygwin... (7 Replies)
Discussion started by: Xterra
7 Replies

3. Shell Programming and Scripting

Need help in batch renaming files with bash shell script.

I have some 50+ files in the following format : abcd_vish_running_ZEBRA_20140818.dat_08-14-2014_23:08:23 abcd_vish_running_ZEB-RA_20140818.dat_08-14-2014_23:08:35 abcd_vish_running_ZEB_RA_20140818.dat_08-14-2014_23:08:37 abcd_vish_running_RI-NG_20140818.dat_08-14-2014_23:08:42... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

4. Shell Programming and Scripting

Batch to bash conversion

Hi, I am just trying to convert the batch script to bash script and i am stuck at one point where I have the below code for /f "delims=" %%a in (a.txt) do ( for /f "tokens=1,2,3* delims==" %%i in ("%%a") do ( for /f "tokens=1,2,3* delims= " %%x in ("%%i") do ( if... (4 Replies)
Discussion started by: prasanna2166
4 Replies

5. Shell Programming and Scripting

Rsync script to rewrite suffix - BASH, awk, sed, perl?

trying to write up a script to put the suffix back. heres what I have but can't get it to do anything :( would like it to be name.date.suffix rsync -zrlpoDtub --suffix=".`date +%Y%m%d%k%M%S`.~" --bwlimit=1024 /mymounts/test1/ /mymounts/test2/ while IFS=. read -r -u 9 -d '' name... (1 Reply)
Discussion started by: jmituzas
1 Replies

6. Shell Programming and Scripting

tftp batch mode within bash script

Hi, I put the necessary tftp commands into a batch file and I can run tftp by $ tftp < tftpbatchscript in bash command line and then successfully exit. Now, I want to put a line which does the same thing above. However, when I put this line into a bash script, the lines below this line... (1 Reply)
Discussion started by: yildiz.a
1 Replies

7. Shell Programming and Scripting

BASH Batch renaming insert additional zero into filename

Hi all, Wondering how this could be accomplished........ a directory contains sequentially numbered files from fw01 to fw999. How would I insert an additional zero so that the directory lists these files in a proper manner? (i.e. all double digit files from fw01 to fw99 would become... (3 Replies)
Discussion started by: putter1900
3 Replies

8. Shell Programming and Scripting

bash - batch processing folder of files by name

Hello Everyone!!! I need some help with a shellscript to batch process a folder of files with the imagemagick convert -append/+append command. The folder contains some hundred or thousand of small images in .png format which I would like to join together in order of their filenames. The... (3 Replies)
Discussion started by: imtombi
3 Replies

9. Shell Programming and Scripting

Help with scritp to count an specific word into a log

Hello my friends, I need to count how many words are into a log file, I'm using: cat logfile | grep 'word' | wc -l Cuz the 'word' appears once per line. But my logfile grow faster and at the end ofthe day is really big, so how i can count the 'word' only from (by example) line 4000 of... (5 Replies)
Discussion started by: lestat_ecuador
5 Replies

10. Shell Programming and Scripting

How to Execute UNIX Scritp on Remote server

Hi Please suggest me How I can Execute UNIX Scritp on Remote server. Thanks Sourabh (2 Replies)
Discussion started by: sourabhshakya
2 Replies
Login or Register to Ask a Question