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.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
Please suggest me How I can Execute UNIX Scritp on Remote server.
Thanks
Sourabh (2 Replies)
Discussion started by: sourabhshakya
2 Replies
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
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
5. Shell Programming and Scripting
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
6. Shell Programming and Scripting
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
7. Shell Programming and Scripting
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
8. Shell Programming and Scripting
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
9. UNIX for Beginners Questions & Answers
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
10. UNIX for Beginners Questions & Answers
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
LEARN ABOUT PHP
mssql_num_fields
MSSQL_NUM_FIELDS(3) MSSQL_NUM_FIELDS(3)
mssql_num_fields - Gets the number of fields in result
SYNOPSIS
int mssql_num_fields (resource $result)
DESCRIPTION
mssql_num_fields(3) returns the number of fields in a result set.
PARAMETERS
o $result
- The result resource that is being evaluated. This result comes from a call to mssql_query(3).
RETURN VALUES
Returns the number of fields, as an integer.
EXAMPLES
Example #1
mssql_num_fields(3) example
<?php
// Connect to MSSQL and select the database
$link = mssql_connect('KALLESPCSQLEXPRESS', 'sa', 'phpfi');
mssql_select_db('php', $link);
// Select some data from our database
$data = mssql_query('SELECT [name], [age] FROM [php].[dbo].[persons]');
// Construct a table
echo '<table border="1">';
$header = false;
// Iterate through returned results
while ($row = mssql_fetch_array($data)) {
// Build the table header
if (!$header) {
echo '<thead>';
echo '<tr>';
for ($i = 1; ($i + 1) <= mssql_num_fields($data); ++$i) {
echo '<td>' . ucfirst($row[$i]) . '</td>';
}
echo '</tr>';
echo '</thead>';
echo '<tbody>';
$header = true;
}
// Build the row
echo '<tr>';
foreach($row as $value) {
echo '<td>' . $value . '</td>';
}
echo '</tr>';
}
// Close table
echo '</tbody>';
echo '</table>';
// Clean up
mssql_free_result($data);
mssql_close($link);
?>
SEE ALSO
mssql_query(3), mssql_fetch_field(3), mssql_num_rows(3).
PHP Documentation Group MSSQL_NUM_FIELDS(3)