Can you ref/link/import a function from external ksh script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can you ref/link/import a function from external ksh script?
# 1  
Old 02-03-2009
Can you ref/link/import a function from external ksh script?

Hey guys,

I'm not the best AIX scripter about but I can flounder my way thru them to create what I need.

Anyhow, I have various scripts that perform various actions and processes. I was tasked to come up with a single form of logging that all the scripts could implement so that the output would be uniform and easy for our monitoring system to parse and use and ends up like this:

Code:
[DEBUG  ] 2009-02-03 14:16:30.000 [user001] [logging.ksh] This is a debug line [-d]
[INFO   ] 2009-02-03 14:16:30.000 [user001] [logging.ksh] logging with an '-i' for [INFO] type
[WARN   ] 2009-02-03 14:16:30.000 [user001] [logging.ksh] logging with an '-w' for [WARN] type
[ERROR  ] 2009-02-03 14:16:30.000 [user001] [logging.ksh] logging with an '-e' for [ERROR] type
[FATAL  ] 2009-02-03 14:16:30.000 [user001] [logging.ksh] logging with an '-f' for [FATAL] type

Essentially I've mimicked log4j, easy enough.

However, rather than go back thru X number of scripts and cut & paste the entire function script I've written into each one, is it possible to simply 'import/reference/inherit' this function (script) into each of the other scripts with a single line?

I'm using ksh to do all this. True, each script that needs to use this logging function will need to implement the proper "log [-diwef] <msg>" calls but I'd rather they do that and all refer to a single script that contains the function than bulk up 10+ scripts with lines and lines of the same code.

I have googled for this but so far nothing comes up with "AIX ksh scripting importing external script" and various of it.

Thanks!
# 2  
Old 02-03-2009
If you're using functions for your logging, you can import that file with '. <path/to/file>'
And I know it might be a bit late, but there is a Log4j variant for shell scripts, called Log4sh
# 3  
Old 02-03-2009
Ah cool.. and.. damn! Smilie


Thanks mate! Problem solved!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass and read an array in ksh shell script function.?

I'm able to read & print an array in varaible called "filelist" I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function. Unfortunately it does not print the entire array from inside the funstion's loop. #/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. Shell Programming and Scripting

In ksh script what is this BEGIN and END in this function?

Can Someone please explain why BEGIN and END statement is used inside function? How does that help in scripting? function fileformatting { CleanupMask="xXxX" sed 's/^.//' < ${AllFile} > ${AllFile}.tmp echo $(wc -l ${AllFile}.tmp) `awk -v CleanupMask=${CleanupMask} ' BEGIN... (2 Replies)
Discussion started by: later_troy
2 Replies

3. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies

4. Shell Programming and Scripting

Activate and deactivate function within a ksh script

Hi, I have written a function which will blink a text "Scanning...". Now in the main script when I am doing the scan in the server I want to call this function so that user will see a blinking text on the screen and at the same time script will proceed will the scan function. Once scan is... (2 Replies)
Discussion started by: suhasingale
2 Replies

5. UNIX for Dummies Questions & Answers

Call external function

Is it possible to call a function from another script? Thanks (6 Replies)
Discussion started by: chrisjones
6 Replies

6. Shell Programming and Scripting

Calling external function in a shell

hi guys, how r u??? please I need you, help me please. I have a shell, in this shell i have this function and another code lines, this function is getting date one day back. the function is in the same shell (FILE 1) Now I need put this function in another file (FILE 2) and calling... (4 Replies)
Discussion started by: acevallo
4 Replies

7. Shell Programming and Scripting

how to import external HASH table in PERL???

hello, I am creating a HASH table using file1.pl :- I want to retrieve the content of the hash table created above from another file named file2.pl :- The problem is that if I separate like this into 2 files.Then it says that HASH table is not created.So can you please tell me how to... (2 Replies)
Discussion started by: nsharath
2 Replies

8. 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

9. Shell Programming and Scripting

external function in awk

Hi all, I have a basic doubt. Is there any way to use external functions (i.e. functions not defined in AWK), in AWK. I have a shell script in which I'm using a AWK snippet. In this snippet I'm calling a function defined in the shell script. But the AWK snippet is not working. I figured that... (5 Replies)
Discussion started by: kamel.seg
5 Replies
Login or Register to Ask a Question