Run an teredata query on linux - linux

I am in badly need of some direction here :) ,there is an batch file(.bat) which runs an teredata query on windows, but for some reasons i will have to use Linux server from now on
test.bat
echo off
bteq < D:\commands.txt > D:\output.txt 2>&1
#echo off goto end
:end #echo exit
commands.txt
.LOGON ------
select (date);
.LOGOFF
how can i do this on red hat - linux? and is it necessary to have bteq utilities or any other Teredata utilities , i have got teredata ODBC drivers on linux though.
it would be great if any one could give an insight onto this ?
Thank you

BTEQ is available on multiple flavours of Windows/Unix/linux including RedHat.
BTEQ can't use ODBC, need to install it plus some other packages like cli.
You just might have to do some minor modifications in your BTEQ script, e.g. backslash to slash in pathname, rm instead of del in .OS.
Otherwise you can run this as a shell script (you just have to decide which Unix shell to use: sh, ksh, bash, etc.), all you can do in a Windows bat can be done in Unix shel, too.
Make the script executable using chmod u+x test.sh
#!/bin/sh
bteq < /...../commands.txt > /...../output.txt 2>&1
and then simply run it from the command prompt.

Related

linux script - substring and append compatibility with unix

I am trying to make my following script compatible with other platforms (unix) and i am not sure if it will be. Especially [[test]] and %%# symbols are compatible. At lease this script works fine on linux.
It would be great if someone (who is familiar with unix) can make some suggestions or fixes to make the following script portable across the platforms (except windows).
#!/bin/sh
INSTALL_HOME=/opt/prod/install0308
export INSTALL_HOME
export CONF_INSTALL_ARGS="-Dinstall.ext.dir=/opt/prod/installExt -Dinstall.alternateExtDir=/opt/dev/installExt/lib -Dinstall.type=OSD"
INSTALL_ALTERNATIVE_TYPES_DIR=''
if [[ ${CONF_INSTALL_ARGS} == *'-Dinstall.alternateExtDir'* ]]; then
INSTALL_ALT_TYPE_DIR_TEMP=${CONF_INSTALL_ARGS#*-Dinstall.alternateExtDir=}
INSTALL_TYPE_DIR=${INSTALL_ALT_TYPE_DIR_TEMP%%-D*}
FINAL_INST_TYPE_DIR="$(echo -e "${INSTALL_TYPE_DIR}" | sed 's/ *$//g')"
INSTALL_ALTERNATIVE_TYPES_DIR=','$FINAL_INST_TYPE_DIR
fi
TOTAL_CONF_ARGS="-Dinstall.ext.dir=${INSTALL_HOME}/lib/provider,${INSTALL_HOME}/lib/security${INSTALL_ALTERNATIVE_TYPES_DIR}"
echo $TOTAL_CONF_ARGS
This is not a compatibility problem between Operating Systems, this is a compatibility problem between Shells.
Your script has been written for bash-like shells, so you just need to replace the first line #!/bin/sh by #!/bin/bash (or any path where bash is located) for it to work on other systems (do not forget to install bash on them).
NB: This script works on your Linux with the shebang #!/bin/sh probably because your Linux distribution has chosen to replace legacy sh by a link to bash or you are explicitly running the script with bash like this: bash ./script.sh.

Why stream redirection operator &>> not working in SUSE linux?

My shell-script is failing on SUSE Linux as the stream-redirection operator I have used (&>>) is not working there, (But it is working fine in Other distributions). How can I correct this. Also I would like to know the standard way of doing the same which is supported by all Distributions?
The command you were using should mean you were using bourne shell:
ls &>> file
this command should redirect both stdout and stderr at the end of file.
Another way to write it, again with a bourne shell could be:
ls >> file 2>&1
However it seems to me this way to write the command will be recognized by more shells, I think for instance ksh will recognize the second form but not the first.
With csh or a csh-like shell you will need to use this syntax:
ls >>& file
Edit: I was confused because depending on the shell you can use &>> or >>& which are not the same.

Shell script giving errors in ksh

I have a script which runs fine when executed in Bash shell (with Red Hat Linux), however this same script which fails on a Solaris 10 (DB) server where ksh is being used to execute this script. This script basically reads line by line from a file and executes a stored proc (in Oracle). Below is my script :
#/bin/sh
for i in $(cat subscriber.txt); do
SUBSCRIBER_ID="'$i'"
sqlplus -s myuser/myuser <<EOF
execute delete_learnings($SUBSCRIBER_ID);
commit;
EXIT
EOF
done
The error I get is :
./removeLearnings.sh: syntax error at line 3: `$' unexpected
Any idea what might be going wrong? Should I change the script to have the ksh? I am not able to debug on this machine since it's a customer environment (which I don't have access to).
The issue is the $(...) construction which is POSIX compliant but unsupported by the legacy Bourne shell which /bin/sh is on Solaris 10 and older.
You can either replace your shebang to call the Solaris POSIX compliant shell:
#!/usr/xpg4/bin/sh
or use this legacy syntax (less recommended):
for i in `cat subscriber.txt`; do
you are trying to execute a sh( bourne shell) script on ksh (Korn shell). Try changing the shebang (#!/bin/bash) to (#!/bin/ksh)
Looping over text files with for is a bad idea, anyway. See http://mywiki.wooledge.org/BashFAQ/001- the recommended syntax is more portable, too:
while read stuff; do
: things with "$stuff"
done <subscriber.txt
You would normally use read -r but I don't know if that's available on Solaris.
However, very often, a shell loop is altogether the wrong approach. A single SQL invocation is a lot better and more robust:
( sed 's/.*/execute delete_learnings(&);/'
printf "commit;\nEXIT\n" ) |
sqlplus -s myuser/myuser

Can I run a Linux shell script in Windows?

I created Shell Script on Linux and it runs fine.
Now I want to run the same script on Windows using gitbash. (Only filepath changed for windows)
I am confused:
do I need to write a new shell script again according to Windows syntax shell script?
or
can a Linux syntax shell script run on Windows without changes?
According TO differences-between-windows-batch-and-linux-bash-shell-script-syntax
Of course you can. There is a tool called cygwin that allows you to do so.
Note that you have to check what the paths are. If so, go to the path you are willing to work on and do pwd. This way, you will get the Windows\kind\of\path.
I use it all the time and it works pretty fine.
You can use Git Bash
It depends on how advanced the scripts are, but simple scripts can be executed in Git Bash.
test.sh contains:
#!/bin/bash
echo Hello World!
Execute script:
./test.sh
Output:
Hello World!
Git Bash vs Cygwin
To answer your question:
#fedorqui in my learning 'cygwin' And 'gitbash' do same stuff for
windows
Git Bash
Git Bash is lightweight and only aims to handle:
version control
a shell that runs commands
Read more: http://openhatch.org/missions/windows-setup/install-git-bash
Cygwin
a large collection of GNU and Open Source tools which provide
functionality similar to a Linux distribution on Windows.
a DLL (cygwin1.dll) which provides substantial POSIX API
functionality.
Read more: https://www.cygwin.com/

Linux command to DOS

I have a file include some linux command and I want to run in on windows (DOS command).
The command is:
cat tmp/$id/index.html | sed -e 's/ID/$id/g' > a;mv a tmp/$id/index.html
What is the similar command in MS-DOS?
Thank you!
The problem is that natively there is no equivalent command to sed. You have two options from my point of view. Either create a vb script that does what you want (It will not take 1 line though - more like 10-15 I guess), or use something like GnuWin32 that gives you the option to run unix commands in windows terminal.
You could consider using powershell to do approximately the same thing. It supports cat and mv and you can get a sed like equivalent by using %{_ -replace "expression", "replace"}. Details here http://blogs.msdn.com/b/zainnab/archive/2007/07/09/grep-and-sed-with-powershell.aspx
Or consider using a linux like command prompt like bash which should be available through cygwin
I think this is impossible to do in "bare" command line (as you called DOS command), because cat and sed are separate utilities. If you want to port this script from Linux command shell to windows command line, I would advise you to download and install CygWin
DOS itself does not have support for that. You could try with a port of SED for DOS available here. If you can get Powershell, that's an option. Here's an example of using grep/sed with Powershell.
There are many options.
You can try to install cygwin or download and install Git and use Git-bash or add the bin directory to your PATH so you can run this command on your CMD prompt.
There is no such command(s) for MS-DOS.

Resources