Help rewriting my KSH-script...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help rewriting my KSH-script...
# 1  
Old 08-19-2008
Question Help rewriting my KSH-script...

Hi!

I'm a beginner at scripting, but have managed to complete a working KSH-script.. Smilie

But since this is going to production i a few weeks, I would like to optimize it and make it better structured!

The idéa of the script is to collect data from the database, put it in a file, and then ftp it to another system.

The file has to look like this, $FILE:
0705959226:0616319971
0705989262:0686317272
0705919275:0656319473
0730907151:066616145


But from spooling the result from sqlplus I got this (and I have to get rid of emty spaces and lines, and non numeric lines)
Numbers.lst:
0705959226 :0616319971

0705989262 :0686317272
0705919275 :0656319473

185 rows selected.



So there is a bit mixturing with the file to make it look good.

The script I made look like this, and it is the red part that I'm frustrated over! It has to be done in a better way:

#!/usr/bin/ksh
#

#Set alias for running enviromet variables
. /.profile

DATA_FILES_DIR=/data_files/Numbers
FILE=Numbers_`date '+%Y%m%d'`
FTPSERVER=
FTPLOGIN=
FTPPASS=
FTPDIR=

export DATA_FILES_DIR FILE FTPSERVER FTPLOGIN FTPPASS FTPDIR

sqlplus /nolog @/scripts/Numbers.sql

cd $DATA_FILES_DIR

awk 'NF >= 2' Numbers.lst > Numbers.tmp
awk 'NF <= 2' Numbers.tmp > Numbers.tmp2
awk '{ print $1 $2 }' Numbers.tmp2 > $FILE
rm Numbers.tmp*
rm Numbers.lst


#FTP file to another system

ftp -n -i $FTPSERVER <<EOF
user $FTPLOGIN $FTPPASS
cd $FTPDIR
put $FILE
quit
EOF

mv $FILE processed




Any idéas or inputs?
Please...

/Linda
# 2  
Old 08-19-2008
sqlplus /nolog @/scripts/Numbers.sql

cd $DATA_FILES_DIR

awk 'NF >= 2' Numbers.lst > Numbers.tmp
awk 'NF <= 2' Numbers.tmp > Numbers.tmp2
awk '{ print $1 $2 }' Numbers.tmp2 > $FILE
rm Numbers.tmp*
rm Numbers.lst

-----------
instead of doing the changes in unix, u can add some more lines into your Number.sql.

use trim(column) for the columns which you used in the sql.

set pagesize 0;
set feedback off;

# 3  
Old 08-19-2008
Thanks!

Great thinking, palsevlohit_123...
Smilie
It worked just fine to make the file ok in sqlplus!
So much easier than in unix.
I'm so thankful!
/Linda
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reverse prior batch job (without simply rewriting the script)

So, let's say I have a usual batch rename file like this: and I'd like to have a secon bat file, that can /reverse" the first. BUT, I don't want to simply "rewrite" it like move hello 254352426 but rather, have the new script take the source and destination and reverse it somehow... (6 Replies)
Discussion started by: pasc
6 Replies

2. Shell Programming and Scripting

Rewriting GNU uniq in awk

Within a shell script I use uniq -w 16 -D in order to process all lines in which the first 16 characters are duplicated. Now I want to also run that script on a BSD based system where the included version of uniq does not support the -w (--check-chars) option. To get around this I have... (7 Replies)
Discussion started by: mij
7 Replies

3. IP Networking

Transparent Proxy with URL Rewriting

All traffic on the LAN is routed through a single machine and filtered using iptables. I'd like to redirect this traffic to a transparent proxy running on the same machine that will rewrite the URL if it matches a specified regex, in which case the user will be redirected to a local server. In... (0 Replies)
Discussion started by: crottyan
0 Replies

4. Shell Programming and Scripting

Rewriting file paths in XML file within bash script

Hi guys, I'm working on a large set of scripts to move files around several servers and manipulate them for our staff. Basically we're shooting things, the videos hit a server and then need organised due to the language they've been shot in. Our XML (designed for Apple's Final Cut Pro) is right... (6 Replies)
Discussion started by: omfgbunnies
6 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. Shell Programming and Scripting

Help with grep (reWriting it in another way.)

Hello everyone!! Nice do be apart of your forum. I am not very good at unix and thats why i need your help i have this project where i have to simulate a grep command without using grep thought. I have to simulate grep <parameters> <file> grep <parameters> <file> grep <parameters> <file>... (6 Replies)
Discussion started by: kenshin88
6 Replies

7. UNIX for Advanced & Expert Users

postfix sender address rewriting

Hi, I have a postfix server that relays to an exchange server. All of my unix/linux systems send to this server, the problem is the form the mail is sent with, the sender address is username@hostname.domain.local I need to rewrite every sender address to unix@maildomain.com for... (0 Replies)
Discussion started by: funksen
0 Replies

8. UNIX for Dummies Questions & Answers

Rewriting a word from location

I am using: ..to get the word that is being searched. What I am looking to do, is to rewrite the word and us it in css: Sort of like this javascript: Hopefully I am making myself clear. Any ideas how I could do this? (1 Reply)
Discussion started by: marringi
1 Replies

9. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

10. IP Networking

Squid Proxy URL rewriting

I have an architecture as below <> <> There is a program in the AIX server which sends SMS to the internet, by sending HTTP request to the SMS processing server. Like, http://smsserver/mysms=test However the application does not have an option to specify where the Proxy server... (1 Reply)
Discussion started by: firdousamir
1 Replies
Login or Register to Ask a Question