I have a script that performs a process on a file.
I want to know how to include a function to run a batch of files?
Here is my script
Code:
#!/bin/bash
#----------------------------------------------------------------------------------------------------------------------
#This script allows the user to import a dsx file
#
# Usage:
#./import.sh -s -d -r -o -f
#
#-----------------------------------------------------------------------------------------------------------------------
dbname="$dbname"
dsn="$dsn"
dsxfile="$dsxfile"
oprange=""
norule=""
verbose=""
reverb=""
module=`basename $0`
DSXLOG_MODULE=$module; export DSXLOG_MODULE
dsxdir="/var/local/dsx/import"
dsximp="/usr/local/bin/dsximp.exe"
dsxpids="/var/run/"
importdir="/var/local/bin/Automated_Testing/Auto_Scripts"
I wrote something like this:
Code:
function batch
{
for dsxfile in $dsxdir/*
do
$dsximp $norule $oprange --dsn=$dsn --dbname=$dbname --user=datasafe --password=datasafe --dsxfile=$dsxdir/$dsxfile
done
Code:
}
function displayHelp()
{
echo ""
echo " Usage: ./import.sh [ -s -d -r -o -f ]"
echo ""
echo " -s, --dsn identified by the Data Source Name "
echo " -d, --dbname Identified by the Database Name "
echo " -r, --norule Do not excecute dsxrule "
echo " -o, --oprange Use optimize range checking "
echo " -f, --dsxfile Identified by the file in dsx format "
echo " -b, --batch Runs the import for a batch of files "
echo " -h, --help Identified by the help menu "
echo ""
}
if [ -e ${dsxpids}$module.pid ]
then
dsxlog $reverb --warning --module="$module" " pid = $$ : Is already running"
true
exit;
else
dsxlog $reverb --info --module="$module" "started pid = $$"
while getopts " s: d: r o f: b e h " option
do
case $option in
f ) dsxfile="$OPTARG";;
d ) dbname="$OPTARG";;
s ) dsn="$OPTARG";;
r ) norule="-r";;
o ) oprange="-O";;
e ) verbose="--verbose";
reverb="--echo";;
b ) batch;;
h ) displayHelp;
dsxlog $reverb --info --module="$module" "displaying --helpmenu";
dsxlog $reverb --info --module="$module" "ended, pid = $$";
exit;;
? | * )displayHelp;
dsxlog $reverb --info --module="$module" "invalid option entered --see helpmenu ";
dsxlog $reverb --info --module="$module" "ended, pid = $$";
exit;;
esac;
done
if [ $# -eq 0 ]; then
displayHelp
dsxlog $reverb --info --module="$module" "no options have been entered --see helpmenu"
dsxlog $reverb --info --module="$module" "ended, pid = $$"
exit 1
fi
$dsximp $norule $oprange --dsn=$dsn --dbname=$dbname --user=datasafe --password=datasafe --dsxfile=$dsxdir/$dsxfile
dsxlog $reverb --info --module="$module" "ended, pid = $$"
fi
hi ,
I need to know commands to be used in the script to invoke batches in order from other scripts and then run those batches,and how to take those logs of those batches which fails........If anyone give me a better idea to complete this entire task in a single script... (5 Replies)
hi is there any way i can display a countdown time needed to run a script? like load a counter at the beginning of the script with the estimated time and display the counter decrementing till it finishes running the script? (3 Replies)
Hi
I would like to run my script to process as many as 50 files at a time.
Currently my script is being called like so:
./import.sh -f filename
so I want to call my script in this way and it must execute every file in the directory
/var/local/dsx/import (1 Reply)
Dear Forum experts
I have the below script which I made to run under bash shell, it runs perfectly for low records number, let us say like 100000. when I put all records (3,000,000), it's takes hours
can you please suggest anything to optimize or to run in different way :-|
{OFS="|";... (6 Replies)
Unix Gurus,
I have a requirement where the shell script needs to do specific tasks after certain period of time.
Daily we receive few files in a particular folder. The script does the file renaming, pass parameters to run some web services and pushes to remote FTP location.
But my... (3 Replies)
Dear all,
I wonder if it is possible that we can run the script
from time to time..I meant, it should repeat the
sourcing of the script by itself? In my case, I need
to source this script manually from time to time,
like once in every 10 minutes.
emily, (2 Replies)
Hi,
I want to write a script that does some sort of health check on the database. It will query the database for information, some query takes long and some are quick.
For example, inside the script I will do something as below:
#!/bin/ksh
run_query_01 &
run_query_02 &... (1 Reply)
I am running a script which will read the data from fail line by line and call the Java program by providing the arguments from the each line.
The Java code is working fast for few records and for some records its getting hanged not providing response for morethan one hour.
Currently am... (4 Replies)
I'm trying to resolve the below scenario by writing bash script.
On my managed linux server I have about 30 accounts and there is not enough space to generate full 30 accounts backup in one go and transfer it via SFTP to my Backup Synology Server. What I'm thinking of doing is breaking the... (3 Replies)
Discussion started by: humble_learner
3 Replies
LEARN ABOUT PHP
pdo_mysql-dsn
PDO_MYSQL-DSN(3) 1 PDO_MYSQL-DSN(3)PDO_MYSQL DSN - Connecting to MySQL databases
The PDO_MYSQL Data Source Name (DSN) is composed of the following elements:
o DSN prefix
- The DSN prefix is mysql:.
o host - The hostname on which the database server resides.
o port - The port number where the database server is listening.
o dbname - The name of the database.
o unix_socket - The MySQL Unix socket (shouldn't be used with host or port).
o charset - The character set. See the character set concepts documentation for more information. Prior to PHP 5.3.6, this element
was silently ignored. The same behaviour can be partly replicated with the PDO::MYSQL_ATTR_INIT_COMMAND driver option, as the fol-
lowing example shows.
Warning
The method in the below example can only be used with character sets that share the same lower 7 bit representation as
ASCII, such as ISO-8859-1 and UTF-8. Users using character sets that have different representations (such as UTF-16 or Big5)
must use the charset option provided in PHP 5.3.6 and later versions.
Example #1
Setting the connection character set to UTF-8 prior to PHP 5.3.6
<?php
$dsn = 'mysql:host=localhost;dbname=testdb';
$username = 'username';
$password = 'password';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$dbh = new PDO($dsn, $username, $password, $options);
?>
+--------+-----------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+-----------------------------------------------+
| 5.3.6 | |
| | |
| | Prior to version 5.3.6, charset was ignored. |
| | |
+--------+-----------------------------------------------+
Example #2
PDO_MYSQL DSN examples
The following example shows a PDO_MYSQL DSN for connecting to MySQL databases:
mysql:host=localhost;dbname=testdb
mysql:host=localhost;port=3307;dbname=testdb
mysql:unix_socket=/tmp/mysql.sock;dbname=testdb
Note
Unix only:
When the host name is set to "localhost", then the connection to the server is made thru a domain socket. If PDO_MYSQL is compiled
against libmysqlclient then the location of the socket file is at libmysqlclient's compiled in location. If PDO_MYSQL is compiled
against mysqlnd a default socket can be set thru the pdo_mysql.default_socket setting.
PHP Documentation Group PDO_MYSQL-DSN(3)