Execute External commands Fitnesse/DBFit from within a Test page - testing

I would like to execute external commands in my test from Fitnesse/DBFit from within a Test page.
For example, as part of a Unit Test:
run a remote ssh command towards host ABC and copy a file with win cp command
run a DB2 load command to import the data in the database from the file
run a stored procedure
verify results
May anyone advice regarding step 1) ?

There's been a few implementations of a CommandLineFixture - google commandlinefixture and you'll find them.

Related

How to run a shell script on another server from kettle job at one server?

Using Pentaho, I want to execute a shell script lying on another server in Kettle Job (.kjb) file using "Execute a Shell script" component. I was successful to run the script locally by giving script file name in that component. But I am not getting how to run a remote script.
Here is how my simple kjb looks like:
Any ideas?
that is pretty straightforward using the shell step from a pentaho job:
1) on General tab check "insert script"
2) on Script tab now you are able to add this inline script:
ssh user#remotemachine 'ls -l'
this will execute ls -l on the remote server via ssh
make sure the ssh user is allowed to login with ssh keys, not asking for password.

Bat file to run a sql query on a schedule through Task Scheduler

I am trying to run a .sql script on a schedule. I have created a batch file to run the script. The script runs fine in sql server management studio and also when I run the batch file content through cmd.
Contents of the batch file:
sqlcmd -S omfmesql -U OMESRV -P orat -i "\\pvsrv-
fsr14\data\Projects\Stat_Table_Creation_unique.sql"
The sql script is supposed to update a stat table. When I run it though cmd and refresh the stat table, the numbers are updated. But when I run this batch file through Task Scheduler, the only action that seems to be performed is running C:\Windows\SYSTEM32\cmd.exe
The task is stated to be completed successfully but the sql query is just not run.
I am not too experienced with Task Scheduler. Any help here would be very much appreciated. Thanks!
Note: I am not intending to use SQL Server Agent
If you have not done so, you need to set the location in Task Scheduler (TS). In at least some versions of TS, this can only be done when you create a basic task, not from the more general "Create Task..." option. Ensure that all the paths in the batch file are absolute or are based in this location.

How to run sql queries in SQL Developer or TOAD and extract result using bat file

Is there a way through which i can execute SQL query in SQL Developer/TOAD and extract the result in any format using .bat file.
I m working on a client machine so using any other software other than SQL Developer/TOAD is not a option.
Please suggest how to create a bat file for the same.
If SQL Developer is installed I venture to guess so is SQL Plus. SQL Developer is simply a graphic interface to the database connections. Try opening a command window, I assume you can since you would like to run .bat programs, and typing in sqlplus. If this comes back with version numbers and a prompt for a user name you should be able to use this for your script.
See this answer on Stack Overflow for more tips on how to run .bat programs from SQL Plus with native SQL Plus spooling.
What version of Toad? If the version of Toad you have has the Automation Designer then you can setup an action to export query results to many different formats. See my answer in this question for steps to export query results to XLS. In step #3 you can choose other formats. Your configured actions can be scheduled or executed by .bat file. Toad's help covers command line execution of these actions.
You can put the following types of sqlcmd statements into a batch file. After running the results are saved to a txt file. This example executes a SQL file already created and saves the results to a txt file.
Step 1: Create SQL file which you want to execute.
Step 2: Execute following sqlcmd command on prompt:
sqlcmd -i SQLFile.sql -S ServerLocation -E -o File.txt
If you are using username and password run following script
sqlcmd -i SQLFile.sql -S localhost -U username -P password -o File.txt
You can run something like this for SQL plus:
sqlplus user/pwd#mydb #SQLFile.sql > File.txt

Teradata client on Unix Solaris

I deploy some .bteq and .sql scripts on a TERADATA database. For doing this, I use a client on my desktop called BTEQWin version 13.10.0.03.
I get the .bteq/.sql from a version control like pvcs/svn etc and all I do once the files are in my workspace folder (from Version control tool), to just drag and drop the files from Windows browser to BTEQWin client (which I connect to a database prior to drag/drop for running those scripts).
Now, I have to automate this whole process in UNIX.
I have written a SHELL KSH/BASH script which is getting all the .bteq/.sql from a TAG/LABEL in the version control tool to a given UNIX folder. Now, all I need to do is the pass these files one by one (i'll take care of the order) to Teradata client.
My ?
- what client do I need to tell Unix admin team to install on Unix server - so that I can run something like below:
someTeraDataCommand -u username -p password -h hostname -d database -f filenametoexectue | tee output_filename.log
Where, someTeraDataCommand is the client / executable - which will let me run Teradata scripts (like I was doing using BTEQWin on my desktop - GUI session). Other parameters can be username, password, which database to connect on what server and which file to run or make that file passed to the command using "<" operator at command line.
Any idea?
- What client ?
Assuming the complete Teradata Tools and Utilities package is installed on your UNIX server (which will have the connectivity tools to talk to Teradata), you should have access to bteq from the command line. Something like this:
bteq < script_file > output_file
Your script file should contain a .LOGON statement to establish the connection:
.LOGON yourTDPID/your_account,your_pw
You might also need to use other commands to set your default database or non-default session values.
Another option would be to combine the SQL and call to BTEQ in a Korn shell script:
#!/usr/bin/ksh
##############
SHELL_NAME=`basename $0`
PRG_NAME=`basename $(SHELL_NAME} .ksh`
LOG_FILE=${PRG_NAME}.log
OUT_FILE=${PRG_NAME}.out
#
bteq <<EOBTQ > ${LOG_FILE} 2>$1
.LOGON {TDPID}/{USERID},{PWD};
--.RUN file=${LOGON}
/* Add your SQL/BTEQ commands here */
.QUIT 0;
EOBTQ
Edit
The double hyphen indicates a single line comment. Typically in a UNIX script you do not leave your password in plain text of a KSH script. The .RUN command would reference a text file in a barely sufficient secure location containing the .LOGON {TPDID}/{USERID},{PWD}; command.
The .RUN command in BTEQ allows you to reference another text file containing a series of valid BTEQ commands that you want to run in the current BTEQ script.
Easiest way is to setup the Solaris TTU, is to request root sudo, and run an interactive installation into defaults as a root. That would cure all client issues.

Failure to connect to derby database using ij from .bat file

I have a java application from which I need to delete and insert data into a local JDBC derby database. I'm trying to execute a SQL script that does this using the ij utility. I've written a batch file to handle this.
C:
C:\Progra~1\Sun\JavaDB\bin\ij.bat
connect 'jdbc:derby:D:\Documents and Settings\user\My Documents\mydatabase';
run "D:\Documents and Settings\user\sqlscript.sql";
disconnect;
exit;
When I run the batch file, the command prompt will execute up to line 2. The ij utility will load in the command prompt, but then the rest of the commands won't be run. I've tested each line by hand and it works fine (as does the SQL script). Is there anything I need to add to the batch file to make the last 4 lines execute? Thanks.
Put these commands in a file called 'commands.txt'
connect 'jdbc:derby:D:\Documents and Settings\user\My Documents\mydatabase';
run "D:\Documents and Settings\user\sqlscript.sql";
disconnect;
exit;
then run ij as follows from your batch file:
C:\Progra~1\Sun\JavaDB\bin\ij.bat commands.txt
You might have the add the exact path to to commands.txt if it is not in your current folder.