Facing issues while running pl/sql script - sql

rebuild the udev rules in the /etc/udev/rules.d/99-oracle-asmdevices.rules file by running the following script:
i=1
cmd="/sbin/scsi_id -g -u -d"
for disk in sdb sdc sdd sde sdf; do
cat <<EOF >> /etc/udev/rules.d/99-oracle-asmdevices.rules
KERNEL=="sd?1",SUBSYSTEM=="block", PROGRAM=="$cmd /dev/\$parent", \
RESULT=="`$cmd /dev/$disk`", SYMLINK+="asm-disk$i", OWNER="grid", GROUP="dba", MODE="0660"
EOF
i=$(($i+1))
Error_Message:
script.sh: line 11: syntax error: unexpected end of file
[root#london1 sf_D_DRIVE]# warning: here-document at line 5 delimited by end-of-file (wanted EOF') -bash: syntax error near unexpected token ('

First, https://www.shellcheck.net/ - bookmark it, use it.
My corrections and tweaks -
#!/bin/bash
i=0
cmd="/sbin/scsi_id -g -u -d"
for disk in sdb sdc sdd sde sdf
do ((i++)); cat >> /etc/udev/rules.d/99-oracle-asmdevices.rules <<EOF
KERNEL=="sd?1",SUBSYSTEM=="block", PROGRAM=="$cmd /dev/\$parent", \
RESULT=="$($cmd /dev/$disk)", SYMLINK+="asm-disk$i", OWNER="grid", GROUP="dba", MODE="0660"
EOF
done

Related

Syntax error at beginning of command when running script

I am trying to run a script with ./insert_data.sh; and I get an error saying there is a syntax error at or near the "."
Am working in PSQL, thanks
Edit #1: My script:
#!/bin/bash
# Script to insert data from courses.csv and students.csv into students database
PSQL="psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c"
cat courses_test.csv | while IFS="," read MAJOR COURSE
do
# get major_id
MAJOR_ID=$($PSQL "SELECT major_id FROM majors WHERE major='$MAJOR'")
# if not found
if [[ -z $MAJOR_ID ]]
then
# insert major
INSERT_MAJOR_RESULT=$($PSQL "INSERT INTO majors(major) VALUES('$MAJOR')")
echo $INSERT_MAJOR_RESULT
# get new major_id
fi
# get course_id
# if not found
# insert course
# get new course_id
# insert into majors_courses
done
Edit #2: Command i'm using to run the script: ./insert_data.sh; Error I'm recieving:
students=> ./insert_data.sh;
ERROR: syntax error at or near "."
LINE 1: ./insert_data.sh;
^
Solved the problem- I had to get out of the PSQL terminal and enter the command within the "project" directory
We can't replicate your case 1:1 because lack of data. But you can always use bash debug with -x flag to see where it actually stuck:
test#test:/tmp$ bash -x ./test.sh
+ PSQL='psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c'
+ cat courses_test.csv
+ IFS=,
+ read MAJOR COURSE
++ psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c 'SELECT major_id FROM majors WHERE major='\''"Sex"'\'''
psql: error: could not connect to server: No such file or directory

Unexpected argument executing cmdexec on a SQL job to export to CSV

I try to run this on a SQL job:
sqlcmd -S . -d CI_Reports -E -s"," -W -Q "SET NOCOUNT ON SELECT * FROM [dbo].[Table]" > D:\Test.csv
How can I fix this error?
Sqlcmd: '> D:\Test.csv': Unexpected argument.
Have you tried like this -
sqlcmd -S . -d CI_Reports -E -s"," -W -Q "SET NOCOUNT ON SELECT * FROM [dbo].[Table]" -o D:\Test.csv
where -o output_file which would identify the file that receives output from sqlcmd.
Additionally you could try BCP which is best suited for bulk coping data between an instance of Microsoft SQL Server and a data file in a user-specified format.
Read more here.

How to read lines from .txt file into this bash script?

I have this bash script which connects to a postgre sql db and performs a query. I would like to be able to read line from a .txt file into the query as parameters. What is the best way to do that? Your assistance is greatly appreciated! I have my example code below however it is not working.
#!/bin/sh
query="SELECT ci.NAME_VALUE NAME_VALUE FROM certificate_identity ci WHERE ci.NAME_TYPE = 'dNSName' AND reverse(lower(ci.NAME_VALUE)) LIKE reverse(lower('%.$1'));"
(echo $1; echo $query | \
psql -t -h crt.sh -p 5432 -U guest certwatch | \
sed -e 's:^ *::g' -e 's:^*\.::g' -e '/^$/d' | \
sed -e 's:*.::g';) | sort -u
Considering that the file has only one sql query per line:
while read -r line; do echo "${line}" | "your code to run psql here"; done < file_with_query.sql
That means: while read the content of file_with_query.sql line by line, do something with each line.

Text Qualifier syntax in PDW dwloader

I am using dwloader utility to load data into PDW. My dwloader syntax is given below:
dwloader.exe -M reload -b 200000 -i \d\Development\Source\FACT.TXT -T Test_DB.dbo.FACT_LOAD -R \d\Development\Bad\FACT_LOAD.bad -t "," -fh 1 -r \r\n -D "yyyy-MM-dd" -E -S 10.1.1.19 -U Devl_User -P Password1> "\d\Development\Log\FACT_LOAD.log"
Pause
I got the data loaded into the table. But all the varchar columns have data within double 'quotes'. My text file is commma delimited. Any idea on how to include the text qualifier in the above syntax?
I figured the answer myself. Including " -s 0x22" in the command above will escape the double quotes.

SQLCMD Usage in Batch file

Hi All I am Writing a Batch Script Which has to read a set of SQL Files which exists in a Folder then Execute Them Using SQLCMD utiliy.
When I am Trying to execute it does not create any output file. I am not sure where I am wrong and I am not sure how to debug the script. Can someone help me out with script?
#echo off
FOR %F IN (C:\SQLCMD*.SQL) DO sqlcmd -S LENOVO-C00 -U yam -P yam!# -i %F -o C:\SEL.txt -p -b
IF NOT [%ERRORLEVEL%] ==[0] goto get_Error
:Success echo Finished Succesffuly exit /B 0 goto end
:get_error echo step Failed exit /B 40
:end
If this is actually in a batch file (not being executed by hand at the command line), then the %F variables need to have the % characters doubled-up because of the way that cmd.exe executes the lines read from the batch file:
FOR %%F IN (C:\SQLCMD*.SQL) DO sqlcmd -S LENOVO-C00 -U yam -P yam!# -i %%F -o C:\SEL.txt -p -b
Though I would have thought you'd get a
F was unexpected at this time.
error if you only had one % character in front of the variable name.
Try to right click the Batch File and run as administrator.
Seems like the answer would be more like this:
FOR %%F "usebackq" IN (`dir.exe C:\SQLCMD*.SQL`) DO ...