How to run sql script in geany? - sqlite

I am able to run my ex1.sql script from the command line, but in geany the follow error pops up:
./geany_run_script.sh: 5: ./geany_run_script.sh: ./ex1: not found
Does anyone have an idea?

Geany cannot execute sql directly. You have to configure the Build Commands from inside the build menu to do this e.g. to psql -f %f to run sql script with psql client.

For me to work I did this
modify the filetypes.sql
this way:
[build-menu]
EX_00_LB=_Exécuter
EX_00_CM=/opt/lampp/bin/mysql -u root < %f
EX_00_WD=
/opt/lampp/bin/mysql = is where mysql is install on my computer
< %f = allow the sql to be executed
dont forget to specify whitch DB you want to work with in your code
so put a line like use Mydatabase;
at the top.

Related

Teradata BTEQ: disable logon prompt

When i run a teradata bteq in the CMD shell -
A little logon prompt screen pops up.
When i press enter the bteq runs.
Is there a way to disable this popup screen?
Searching the internet yields that entering a logonprompt off should solve the problem.
Like so:
.SET LOGONPROMPT OFF
.LOGON my_server
-- rest of the bteq script...
.QUIT
.LOGOFF
I use the following shell command to run the bteq:
bteq < myscript.sql > log.txt
Could you please help me get rid of the logon popup screen?
You can pass the fully qualified logon string to get rid of the prompt.
.LOGON my_server/user,password
If you still want to go with only the server details in .LOGON. Along with .SET LOGONPROMPT OFF, set the environment variable GUILOGON as NO.
In CMD: setx GUILOGON NO
Snippet from TD Documentation:
Note that setting LOGONPROMPT to OFF is sometimes not going to be
sufficient for suppressing all unnecessary prompts when using Windows
BTEQ. You may also need to instruct CLI to suppress its generation of
what is known as its GUILOGON dialog box.
This can be accomplished by setting the environment variable GUILOGON
to NO.

Error while running a .sh script via QProcess

I have written a QT GUI program where pressing a button will execute a .sh script. The contents of the script is-
echo -e 'attach database 'testdatabase.db' as 'aj';\n.separator ","\n.import ora_exported.csv qt_ora_exported' | sqlite3 testdatabase.db
basically the script will import a .csv to an sqlite database. And when the script file (script.sh) is run manually from linux terminal ($./script.sh) it successfully imports the .csv file into the database table.
But, when I call the script from my QT program
void MainWindow::on_importButton_clicked()
{
QProcess process;
process.startDetached("/bin/sh",QStringList()<<"/home/aj/script.sh");
}
it compiles successfully but gives an error message in console when the button is pressed at runtime.
Error: near line 1: near "-": syntax error
Error: cannot open "ora_exported.csv"
what could be causing this ???
EDITED
I have changed my .sh script now to--
echo -e 'attach database 'testdatabase.db' as 'aj';\n.separator ","\n.import /home/aj/ora_exported.csv qt_ora_exported' | sqlite3 testdatabase.db
Thus providing the path to my ora_exported.csv. As a result the runtime error [Error: cannot open "ora_exported.csv"] has gone but the other message [Error: near line 1: near "-": syntax error] is still coming.
Same as was observed in previous case, using ./script.sh is successfully importing data to sqlite3 db table file but QProcess is unable to.
echo is a built in command of a shell that may behave differently.
E.g. take this test script: echotest.sh
echo -e "123"
Now we can compare different results:
$ bash echotest.sh
123
$ zsh echotest.sh
123
$ dash echotest.sh
-e 123
You are probably on some Ubuntu-like OS, where /bin/sh redirects to dash. That would explain the error around "-". So if you are using echo, set you shell specificially or ensure that your script works on all common shells.
Additionally, you are messing up your quotations
echo -e 'attach database 'testdatabase.db' as 'aj';\n.separator ","\n.import /home/aj/ora_exported.csv qt_ora_exported'
results in (no quotations in the first line)
attach database testdatabase.db as aj;
.separator ","
.import /home/aj/ora_exported.csv qt_ora_exported
but you pobably want
echo -e "attach database 'testdatabase.db' as 'aj';\n.separator ','\n.import /home/aj/ora_exported.csv qt_ora_exported"
It looks strange that you are using external script to update database!
why you don't pass "ora_exported.csv" file name as a script argument? This would help solve the problem.
I was talking (typing) about this solution:
void MainWindow::on_importButton_clicked()
{
QProcess::startDetached("/bin/sh",
QStringList()<<"/home/aj/script.sh",
"<location of: 'ora_exported.csv' file>");
}

Installing an MSP using Powershell works on the local machine, fails remotely. Why?

I need some Powershell advice.
I need to install an application's MSP update file on multiple Win08r2 servers. If I run these commands locally, within the target machine's PS window, it does exactly what I want it to:
$command = 'msiexec.exe /p "c:\test\My Application Update 01.msp" REBOOTPROMPT=S /qb!'
invoke-wmimethod -path win32_process -name create -argumentlist $command
The file being executed is located on the target machine
If I remotely connect to the machine, and execute the two commands, it opens two x64 msiexec.exe process, and one msiexec.exe *32 process, and just sits there.
If I restart the server, it doesn't show that the update was installed, so I don't think it's a timing thing.
I've tried creating and remotely executing a PS1 file with the two lines, but that seems to do the same thing.
If anyone has advice on getting my MSP update installed remotely, I'd be all ears.
I think I've included all the information I have, but if something is missing, please ask questions, and I'll fill in any blanks.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
My process for this is:
Read a CSV for server name and Administrator password
Create a credential with the password
Create a new session using the machine name and credential
Create a temporary folder to hold my update MSP file
Call a PS1 file that downloads the update file to the target server
>>> Creates a new System.Net.WebClient object
>>> Uses that web client object to download from the source to the location on the target server
Call another PS1 file that applies the patch that was just downloaded –>> This is where I’m having issues.
>>> Set the variable shown above
>>> Execute the file specified in the variable
Close the session to the target server
Move to the next server in the CSV…
If I open a PS window and manually set the variable, then execute it (as shown above in the two lines of code), it works fine. If I create a PS1 file on the target server, containing the same two lines of code, then right click > ‘Run With PowerShell’ it works as expected / desired. If I remotely execute my code in PowerGUI, it returns a block of text that looks like this, then just sits there. RDP’d into the server, the installer never launches. My understanding of the “Return Value” value is that “0″ means the command was successful.
PSComputerName : xx.xx.xx.xx
RunspaceId : bf6f4a39-2338-4996-b75b-bjf5ef01ecaa
PSShowComputerName : True
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId : 4808
ReturnValue : 0
I even added a line of code between the variable and the execution that creates a text file on the desktop, just to verify I was getting into my ‘executeFile’ file, and that text file does get created. It seems that it’s just not remotely executing my MSP.
Thank you in advance for your assistance!
Catt11.
Here's the strategy I used to embed an msp into a powershell script. It works perfectly for me.
$file = "z:\software\AcrobatUpdate.msp"
$silentArgs = "/passive"
$additionalInstallArgs = ""
Write-Debug "Running msiexec.exe /update $file $silentArgs"
$msiArgs = "/update `"$file`""
$msiArgs = "$msiArgs $silentArgs $additionalInstallArgs"
Start-Process -FilePath msiexec -ArgumentList $msiArgs -Wait
You probably don't need to use the variables if you don't want to, you could hardcode the values. I have this set up as a function to which I pass those arguments, but if this is more of a one-shot deal, it might be easier to hard-code the values.
Hope that helps!
using Start-Process for MSP package is not a good practice because some update package lockdown powershell libs and so you must use WMI call

Teradata - run a file/script at Unix Linux command prompt

I have the client/TTU installed on Unix box for Teradata.
If I do the following, it works. Where "..." is Teradata BTEQ normal output and once the following is done, I'm back at the prompt.
$ bteq
...
....
. logon dbname/dbuser,dbpassword
SELECT DATE, TIME;
.LOGOFF;
.QUIT;
..
...
$
Now, lets say I put the following lines in a file called "testtd.bteq"
. logon dbname/dbuser,$dbpassword
SELECT DATE, TIME;
.LOGOFF;
.QUIT;
What I want now is ... how can I run this script (.bteq) at Unix $ prompt ???
I tried the following methods so far, but they didn't work, may be Im missing anything:
1. bteq < /path/to/testtd.bteq > testtd.log
2. bteq <
.run /path/to/testtd.bteq
HereDocEndsHere
Any ideas? DO I HAVE to provide ". logon dbname/dbuser,dbpassword" FIRST, if I'm using the HereDocument way?
Running bteq command on $ prompt doesn't even give me any HELP/options that I can use, like other commands.
i.e.
cmd -u user -p password -f file etc...
The best practice I'm aware of is
store your teradata credentials in a ~/.tdlogon file
create a script that contains your bteq call with all the stuff it needs.
E.g., create a file bteqScript.sh with
/* define helper variables, e.g.... */
export ARCHIVEDIR=~/data
export DATAFILE=dataOutput1.txt
bteq <<EOF
.run file=$HOME/.tdlogon
.export data file=${ARCHIVEDIR}|${DATAFILE}
/* sql code on next line(s) */
select
'foo' as "bar"
;
.export reset
EOF
Note that .run file=... executes the .logon command with your credentials, stored elsewhere.
Kudos to Alex Hasha for the bteq script.
PS - It works via method 1 -- when I hard code the password in the script file for LOGON command.
I wanted to do the same via exporting a variable called "dbpassword"
i.e.
$ export dbpassword=xyxyxyxyx
and
then, inside the script file, i can use "$dbpassword" ... in the LOGON command.. somehow export is not exporting the var within .bteq logon command.

Pydev Eclipse console does not support curses.setupterm

I cannot run a script in Eclipse that works perfectly in a terminal.
It seems that Eclipse console cannot support some functions. I am looking for a workaround to be able to debug the script using Pydev.
Is it possible to set PyDev to use for example /usr/bin/gnome-terminal instead of the Eclipse native console ?
Otherwise it there a way to define a wrapper as a python interpreter for PyDev that will launch an terminal external to Eclipse (I've tried but failed on that).
Thank you
Nga
Right now, curses-based apps really don't run well inside Eclipse/PyDev, so, you must really launch it externally. To debug you can use the remote debugger: http://pydev.org/manual_adv_remote_debugger.html
If you use Aptana Studio, there's a terminal view which should emulate a terminal better... try running python (i.e.: running your program) from inside that view. If it does work properly there, maybe I could check a way to better integrate there and launch directly in that view.
Thank you for your reply. I have finally defined kind of a wrapper as a bash script calling python in a xterm. Pydev is checking some configuration by calling eclipse/plugins/org.python.pydev_2.4.0.2012020116/PySrc/interpreterInfo.py so the script first echo the format expected by PyDev. here is the script "
#!/bin/bash
# dummy return for Eclipse Pydev - respect interpreter info format
echo "EXECUTABLE:/home/user/python_custom/python_xterm|
|/home/user/eclipse/plugins/org.python.pydev_2.4.0.2012020116/PySrc
|/usr/lib/python2.5
|/usr/lib/python2.5/plat-linux2
|/usr/lib/python2.5/lib-tk
|/usr/lib/python2.5/lib-dynload
|/usr/local/lib/python2.5/site-packages
|/usr/lib/python2.5/site-packages
|/usr/lib/python2.5/site-packages/Numeric
|/usr/lib/python2.5/site-packages/PIL
|/usr/lib/python2.5/site-packages/gst-0.10
|/var/lib/python-support/python2.5
|/usr/lib/python2.5/site-packages/gtk-2.0
|/var/lib/python-support/python2.5/gtk-2.0
|/var/lib/python-support/python2.5/HTMLgen
|/var/lib/python-support/python2.5/pyinotify
|/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode
|/usr/lib/site-python
#
$
|__builtin__
|__main__
|_ast
|_codecs
|_sre
|_symtable
|_types
|errno
|exceptions
|gc
|imp
|marshal
|posix
|pwd
|signal
|sys
|thread
|xxsubtype
|zipimport
"
# activate scrollbar -sb with 6000 lines
# allow logging -l with filename log_$NOW
xterm -g 150x100+0+0 -sb -sl 6000 -si -hold -e "python $*"
that does the job, and I can use Pydev and its debugger

Resources