Difficulty with incrementing Variables and using the results in a If/else statement
Environment:
BASH version: GNU bash, version 3.2.51(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2007 Free Software Foundation, Inc.
OS: Oracle Solaris 10 9/10 s10s_u9wos_14a SPARC
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
Assembled 11 August 2010
Script:
#-------------------------------------------------
# This sftp's the files to the remote server
#
#load global variables
#---------------------------------------------------------- #If hostname = production server then use one #account, if it equals anything else use the test account
#grab the account used for the transfer and load just the domain name for logging later
#check to see if there are any files named *.txt in the /transfer directory
#see if they are newer that the ~/.newer file and if they are send them via SFTP to $HOSTIS
#sftp any files found, if none found or all sent goto RESULT
#make a log entry with a datetime stamp that each file was transmitted
#for each file sent increment $SENT by 1 #If any files are sent email the user that the files were successfully sent else die.
So this has been giving me fits and I just can't figure it out. I am sure it's a rookie mistake but I have been staring at it too long and can't find it. The bit I am having trouble with is the SENT variable increment and using to determine which part of the if statement to execute.
Doesn't matter how I change it SENT=0 when it gets to the second if statement and it always executes the first condition rather than the second.
It has something to do with global vs local variables I think but I can't figure out how to correctly configure it.
Any teaching would be appreciated.
Last edited by os2mac; 12-18-2012 at 10:56 AM..
Reason: to correct conditional syntax...
if so, wouldn't $SENT always increment by 1 even if there were no files sent?
If that's the case, how would I code for that condition, basically what I am trying to do is keep track of whether files were sent and then send an email to the user notifying them of such else die.
Yes my comment still holds true. Right now, $SENT will never be incremented, It needs to be placed outside the here document, and you would need to test if it can be incremented..
Last edited by Scrutinizer; 12-18-2012 at 07:37 AM..
so after YOU got $SENT incrementing, it still wouldn't send. Turns out the problem was the conditional was incorrectly stated for some reason rather than -eq or == I had to use !=.
also in this iteration it will send an email for EACH file. How could I set it up for sending only one file for all files at the end of the loop?
Requirement 1) I need to execute 15 SQL queries in oracle through linux script. All these query results needs to be stored in array variables.
Requirement 2) And these 15 queries needs to be executed in parallel.
Requirement 3) Once all the queries executed then the shell script should... (3 Replies)
Hi,
I am new to linux...
How to Assign SQL Query Results to Variables in Linux,i want ti generate it in param files, Can anyone please explain me.
Ex: SQL> Select * from EMP;
O/P: Emp_No Emp_Name
1 AAA
2 BBB
3 CCC
and I want expected... (5 Replies)
Hello,
I am very new to shell scripting and I am not sure of how best to handle the following scenario. I need to query a list of values from a table. I need to store those results and use them to selectively delete values in yet another table in a separate database. I do know how to store the... (3 Replies)
While assisting a forum member, I recommended running SQL/Plus in a coprocess (to make database connections and run a test script) for the duration of his script rather than starting/stopping it once for every row in a file he was processing.
I recalled I made a coprocess example for folks at... (2 Replies)
I want to store the sql query output into a variable
#!/bin/ksh
ORACLE_SID=DB01;
export ORACLE_SID;
export FILE_PATH=/home/asg/Tmp
# Order Checking
echo " removing old files "
rm $FILE_PATH/Malformed_Order.txt
echo " Enter the Malformed Order ....!"
read orders
echo "Regrade... (5 Replies)
Hi
I would like to know if there is a way to just have one ORACLE connection established, using which we can execute different queries and store the results under different variables.
For e.g the following uses to two silent ORACLE connection to store the result under two different... (4 Replies)
Hi All,
I needed to get the result of two sqlplus queris into shell variables.
After days of looking for the ultimate solution to this problem.. i found this...
sqlplus -s USER/PASS@DB <<EOF | awk '{if(NR==1) printf("%s ", $1); if(NR==2) printf("%s ",
$1);}' | read VAR1 VAR2
set head off... (2 Replies)
First: me == noob. Whats a good resource for shell script info cause I'm having trouble finding good info.
I'm writing a shell script to automate the setup of a flash 'page flip'.
My current code is below.
the page flip takes an xml file of format
<content>
<pages... (1 Reply)
Hello
I would like to perform a select from a oracle table and return those values to my shell script
For example:
site=head -1 $infile | cut -c1-15 | awk '{printf "s%", $0}
sqlplus -s /nolog |& #Open pipe to sql
select col1, col2, col3, col4
from oracle_table
where col5 =... (6 Replies)