unix script for conditional execution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unix script for conditional execution
# 1  
Old 07-14-2009
unix script for conditional execution

Below is my shell script. I am trying to execute two different BTEQ scripts depending on the day of the week. So on a saturday I will execute a certain BTEQ script and on other weekdays I will run the other script.

#!/bin/ksh
dt=`date +"%a"`
if [$dt -eq "Sat"] then
bteq > final_output <<- EOF
.run FILE=/home/i276764/tdata_logon.txt
.run file=/home/i276764/insert_sql_sat.txt
else
bteq > final_output <<- EOF
.run FILE=/home/i276764/tdata_logon.txt
.run file=/home/i276764/insert_sql_wkday.txt
fi
exit 0


my script gave errors like unexpected else and then unmatched < operator.

I would appreciate help on this.

Thanks in advance.
# 2  
Old 07-14-2009
Quote:
Originally Posted by Mihirjani
HTML Code:
dt=`date +"%a"`
if [$dt -eq "Sat"] then
You try to compare string as integer, see UNIX man pages : test ()
Code:
dt=`date +"%a"`
if [[ $dt = "Sat" ]]; then

# 3  
Old 07-14-2009
I took your advise and used the script below(made it simpler to see if it worked) and still get the error else statement unexpected... :-(

#!/bin/ksh

dt=`date +"%a"`

if [[$dt -eq "Sat"];] then echo "Saturday"
else echo "Other"
fi
# 4  
Old 07-15-2009
use a ";" between "]]" and "then" and space out [[ ]] from condition
instead of eq use =
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Bashrc File - Conditional Command Execution?

Hello All, I was wondering if there is a way to execute a command in my ".bashrc" file based on how I logged into the PC? I was thinking maybe there is a way to check how the user (*myself) logged in, maybe somehow with the who command along with something else, but I'm not sure... I know I... (7 Replies)
Discussion started by: mrm5102
7 Replies

2. Shell Programming and Scripting

Conditional execution

Here's an interesting (to me, anyway) little puzzle. Background: I have a process that restores a number of large(ish) files from tape backup. As an individual file is being written, it is owned by root, then the ownership is changed when that file is complete. Since this process can take... (3 Replies)
Discussion started by: edstevens
3 Replies

3. Shell Programming and Scripting

Conditional Execution of a Script.

I have a unix shell script Test.sh more Test.sh echo "Calling dbquery1.sh...." ./dbquery1.sh echo "Calling dbquery2.sh...." ./dbquery2.sh more dbquery1.sh sqlplus -s user1/password1@DB_SID @/tmp/storedprocedures/Hello.rcp I run Test.sh However, I do not want dbquery2.sh to be... (3 Replies)
Discussion started by: mohtashims
3 Replies

4. Shell Programming and Scripting

search and conditional execution

Hi, I have a list of files with different filenames like nam0001.txt,pan0001.txt etc coming in /data/inbox from various places. I needed a shell script which would:- 1)searches for a word from the filenames (coming in inbox directory) provided in input parameter. 2)if found, put in... (2 Replies)
Discussion started by: Saiesh
2 Replies

5. Shell Programming and Scripting

Execution of Unix script after every second without crontab

Hi, I have shell script "A" which is executing oracle pl/sql procedure and initiate its multiple threads at a time as below on given user value in an other script "B". I want to execute script "A" after every second with out cron tab as " A " will keep on executing after every second till... (1 Reply)
Discussion started by: saad.imran@gmai
1 Replies

6. UNIX for Dummies Questions & Answers

Conditional execution of statements

Hi , I have a script which has multiple awk and sed commands like below. First one :- find /root/src/ -name "*csv" -size 0 -exec rm {} \; Second one: - ls *SRE*.txt > SRT_TRAN.dat rm *asr*.txt Third one :- find /root/src/ -name '*.csv' | while read FILENAME ; do awk... (2 Replies)
Discussion started by: shruthidwh
2 Replies

7. Shell Programming and Scripting

Conditional execution

Hi All, I want to echo a message in case a system is reachable by ping or echo a different message in case it's not reachable. Sample code i wrote is ping localhost -n 2 | grep 'ttl' > ping_op; ls ping_op > /dev/null && drReachable=Alive; echo -e `date`: \\t "DR server is reachable" >>... (5 Replies)
Discussion started by: Mr. Zer0
5 Replies

8. Shell Programming and Scripting

Help on shell script conditional execution when CPU Idle > 60%

I need a shell script that will monitor a few conditions and not execute until the these conditions are met. The problem I'm having is that I can not perform a database snapshot (backup) of a sybaseIQ database unless the CPU Status Idle % is above 60% or the snapshot (backup) fails. If... (2 Replies)
Discussion started by: pancona99
2 Replies

9. Shell Programming and Scripting

Conditional execution and parallel jobs

how can i process jobs parallel with conditions below. Script1.ksh Script2.ksh Script3.ksh Script4.ksh Script5.ksh Script6.ksh Script7.ksh Script8.ksh Script9.ksh Script10.ksh After successful completion of Script1.ksh I need to run Script7.ksh. After successful... (4 Replies)
Discussion started by: ford2020
4 Replies

10. UNIX for Advanced & Expert Users

Unix script execution messages

Hi folks, Is there a way to view the messages, during execution of a unix script?, for the purpose of debugging. Regards (2 Replies)
Discussion started by: JimJim
2 Replies
Login or Register to Ask a Question