How to call ./snowsql file from a bash script on Mac? - snowflake-cloud-data-platform

I am trying to make a connection from a bash script, accomplishing something similar to this:
rmcguigan$ snowsql --filename test.sql
* SnowSQL * v1.1.86
Type SQL statements or !help
+----------------+
| GREATEST(1, 2) |
|----------------|
| 2 |
+----------------+
1 Row(s) produced. Time Elapsed: 0.108s
So I am running a bash file with chmod 755
>./test.sh
This is the contents of the file
./snowsql test.sql
syslog -s -l "Good to go"
results
rmcguigan$ ./test.sh ./test.sh: line 3: ./snowsql: No such file or
directory Unknown level: Good to go
How should my bash script call ./snowsql test.sql ?

It looks like the problem is that you have ./snowsql test.sql in your test.sh file, which tries to find and execute a file named snowsql in the current directory rather than running the command with that name. Try removing the ./ and using the --filename argument so that the file looks like this:
snowsql --filename test.sql
Make sure that you have a file named test.sql in your current directory as well with whatever SQL statement you want to execute.

Related

Opening File with emacsclient from windows

I try to open a File from within Windows10 in an emacsclient running on wsl2/Debian.
Upon startup I launch wsl/debian, X410 as X-server and the emacs daemon.
I can start a new emacs frame with emacsclient with the following startclient.bat:
#echo off
debian.exe run "if [ -z \"$(pidof emacsclient)\" ]; then export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0; emacsclient -c; pkill '(gpg|ssh)-agent'; fi;"
Then I created a shortcut so I can open a new emacs frame from the taskbar. To my surprise it works quite smoothly... so far. However, I can not figure out how to open a file with the emacsclient from within windows explorer.
I guess I would need to pass an argument to the emacsclient -c in the bat file, but how do I do this?
EDIT:
by doing the following:
debian.exe run "if [ -z \"$(pidof emacsclient)\" ]; then export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0; emacsclient -c "%1"; pkill '(gpg|ssh)-agent'; fi;"
I can open a file with emacsclient with:
startclient.bat file.txt
However when using open with the path to the file is messed up
instead of
/mnt/c/Users/path/to/file
I get
/mnt/c/Windows/system32/C:\Users\path\to\file
How would I go about passing the correct path as variable?
Not quite sure where the /mnt/c/Windows/system32/ is coming from, but you can convert the C:\Users\path\to\file into /mnt/c/Users/path/to/file by surrounding the %1 argument with wslpath, as in something like:
emacsclient -c "$(wslpath '%1')"

Concatenate two GSUtil Command

I want to execute two gsutil command in a single line, how can i achieve that.
For ex:
gsutil ls gs://projectname/bucketname/folder1/folder2/filename.png | \
cp gs://projectname/bucketname/folder3/folder4/
Find/ List a file from specific bucket and copy the same file to the bucket folder. In the above command i'm using ls (list) and cp (copy) command, but this is not working as expected.
Something similar to the below shell script or linux command, we use exec and continue the next command right.
find -type f -path '*schedule*/*' -name "*.png" -exec cp -n {} /tmp/MusicFiles \;
Your early response is highly appreciated. Thanks in advance..!
Oneliner: From gsutil help cp:
-I Causes gsutil to read the list of files or objects to copy from
stdin. This allows you to run a program that generates the list
of files to upload/download.
So, some_program | gsutil -m cp -I gs://my-bucket.
Where some program can be gsutil ls ...
Additionally,
gsutil accepts wildcards, so that command would be something like this.
gsutul cp gs:/bucket-name/*schedule*/*/*.png gs://bucketname/folder3/folder4/
Notice that there it is possible to do single star * and double star ** for recursive wildcards.

Create a bat file for git-bash script

Hi all. I gave a git-bash installed and want some automatisation. I've got a .bat file, which I want to run as
some.bat param | iconv -cp1251 > l.log | tail -f l.log
And I want to run it not in WinCMD but in git-bash shell - tell me plz how to do it?
Git bash on windows uses BASH. You can use bash to create a quick script that can take in parameters and echo them so that you can pipe them to your next utility.
It could look something like this
File: some.sh
#!/bin/bash
#Lots of fun bash scripting here...
echo $1
# $1 here is the first parameter sent to this script.
# $2 is the second... etc. $0 is the script name
then by setting some.sh as executable
$ chmod +x some.sh
You'll then be able to execute it in the git-bash shell
./some.sh param | cat ... etc | etc...
You can read about bash programming
I'd reccomend looking at some bash scripting tutorials such as this one

reading latest from sftp server

I have a requirement to download the latest file from sftp server.I have written the below code in shell script but am not able to download the file.
After retrieving the file am getting the below Error
Invalid command
Please help me how to download the file.
#!/bin/sh
HOST='xx.xx.xx.nxx'
USER='xx'
PASSWD='xx'
sftp $USER#$HOST <<EOF
cd /inbound
file=$(ls -ltr *.xml | tail -1 | awk '{print $NF}')
get $file
EOF
You are trying to run shell commands in sftp, but sftp is not a shell. The command ls happens to exist in sftp, but not $(), tail, or awk. To see this, just type sftp $USER#$HOST to open a sftp session and type help to get all of the available commands.
So what you need to do is to execute the shell commands using ssh to get the filename. So something like this:
file=$(ssh $USER#$HOST "ls -ltr /inbound/*.xml" | tail -1 | awk '{print $NF}')
This execute the command ls -ltr /inbound/*.xml remotely on the server. The output of that is then processed by your shell script locally. Or maybe more efficiently by doing the processing on the server:
file=$(ssh $USER#$HOST "ls -ltr /inbound/*.xml | tail -1 | awk '{print \$NF}'")
Now the shell variable file contains the name of the newest file. Then you can download that file with sftp as
sftp $USER#$HOST:$file .

Oracle DB backup script not running

I am trying to make a backup using crontab on a linux machine.
I have a short script :
#!/bin/bash
export ORACLE_HOME=<oracle_home_directory>
DATE=`date +%F_%H-%M-%S`
echo $DATE
/u01/app/oracle/product/11.2.0/dbhome_1/bin/expdp system/oramanager full=Y parallel=4 directory=data_pump_dir dumpfile=prod1-ecmdb1-$DATE.dmp logfile=prod-ecmdb1-$DATE.log compression=all
I have placed this script in crontab as such:
02 17 * * * cd /u01/app/oracle/admin/ecmdb1/dpdump/ && /u01/app/oracle/admin/ecmdb1/dpdump/backup.sh > /tmp/test.out
But the script does not run. It says in logs that :
UDE-12162: operation generated ORACLE error 12162
ORA-12162: TNS:net service name is incorrectly specified
If I run the whole script line manually, it works fine. But doesnt work fine using cron. Do I need to setup variables ?
Set ORACLE_HOME AND ORACLE_SID
export ORACLE_HOME=/u01/oracle/product/......
export ORACLE_SID=dbname
Add export ORACLE_SID=<...>
And make sure the cron is set up under the same user, not root.
Here's the working script, after using all the help from Community.
Create a Bash file(used nano here):
nano DBBackUp.sh
Copy the below code and edit the contents in angle brackets:
#!/bin/bash
export ORACLE_HOME=<OracleHomeDirectory>
export ORACLE_SID=<SID>
DATE=`date +%d%m%Y`
DATETIME=`date +%F_%H%M%S`
echo $DATETIME | tee DBBackUp_$DATE.log
echo "Exporting..." | tee -a DBBackUp_$DATE.log
$ORACLE_HOME/bin/expdp <SCHEMA/PASSWORD> directory=DP dumpfile=BACKUP$DATE.dmp | echo export.log | cat export.log >> DBBackUp_$DATE.log
echo "Compressing..." | tee -a DBBackUp_$DATE.log
zip BACKUP$DATE.zip BACKUP$DATE.dmp >> DBBackUp_$DATE.log
echo "Deleting..." | tee -a DBBackUp_$DATE.log
rm BACKUP$DATE.dmp 2>&1 | tee -a DBBackUp_$DATE.log | cat DBBackUp_$DATE.log
Create a cronjob:
00 13 28 04 * /home/oracle/DBBackUp/DBBackUp.sh
Above cronjob executed at 01:00pm on 28th April 2020
System creates export.log in DP directory.
Here, all the files are in same location. [DP Directory]
Make sure that oracle user's having necessary permissions & ownership to the shell script.

Resources