When you test your functions, do you always create a separate script to call that function?
Yes, i do that. It is called "regression test" because functions in my library usually do some pretty abstracted things and i want them to be as reliable as possible. If you search the forums for my name and "ksh function" you will even find some examples of what i wrote.
My usual setup is like this:
i have my library in "/usr/local/lib/ksh" and all my function names start with "f_". This way i know immediately which are external functions and which are not in complex scripts.
I have one "environment" function, which i source in at the beginning of every script and which sets the environment from the beginning, including PATH, FPATH and so on. This way i have always the same environment in every script i write and don't have to worry about scripts being started from crontab and similar common problems.
In addition i have one environment variable "DEVELOP", which is tested in the environment function. If it has any value at all FPATH is not set to "/usr/local/lib/ksh" but to "~/lib", so that a local copy of the library in my $HOME is used. This way i can locally test the scripts with new versions of the lib functions (my user has this variable set in ".kshrc") and then just roll out the scripts. Other users don't have the variable set so they will automatically use the general version of the library with no change.
usual script start:
f_env would look like this (parts):
There are also parts dealing with supported alerting systems (BMC Patrol, HP OpenView, and some other are supported), and some site-dependent stuff, but i think you get the drift.
Notice the "if [ -z "$DEVELOP" ]" line, where the FPATH is set accordingly.
I hope this helps.
bakunin
These 2 Users Gave Thanks to bakunin For This Post:
I don't understand why is doesn't work when I run it from within the bash shell using 'ksh functionname'
Have a close look at what is inside the function file: there is only the function definition, not a call to it!
if you enter the following into ksh (or bash, doesn't matter):
what will happen? Nothing! YOu have defined what the shell should understand when you issue "foobar" at the command line, but not issued it! Now try the following (with a new shell):
It will now print "hello world.", because you ahve first defined the function (line 1-4) and then called it (line 5).
I understand, but I call the function, not the file.
As long as the file in which the function is is in $FPATH, and I call it from another directory so I don't run the script instead using 'ksh functionname', it should work. It works this way on my other system running Solaris:
I understand, but I call the function, not the file.
As long as the file in which the function is is in $FPATH, and I call it from another directory so I don't run the script instead using 'ksh functionname', it should work.
Agreed. Maybe the FPATH isn't set to what you think it is. After all, issuing ksh functionname invokes another shell, which has its own environment. You might try, for debugging purposes, to do
Hi Experts,
Am writing a code which need to check for the previous day date and pickup the file as per the previous day date.
Problem: Why variable "YDATE" is empty ?
O/S: RHEL 5.6
Shell: BASH
Desired O/P: ls -lrt /opt/test/user/atsuser.NHU/out/demon.08272017
When I checked the... (3 Replies)
I am unable to run java from jdk.
it says "cannot execute binary file"
I downloaded the jdk again freshly but the problem still persists.
All files have execution permission.
Both OS and JDK are 64bit.
Please help me out.
$ pwd
/home/XXXXX/apache-tomcat-6.0.18/jdk1.5.0_14/bin
$... (2 Replies)
Hello,
I am trying to create a ksh script to login to server and collect gather output of some command to troubleshoot some issue.
DATE=`date +%b.%d.%Y.%M.%H`
echo " Enter emp id to login to server"
read Eid
Eid=$Eid
echo " Enter hostname of the system"
read HOST
HOST=$HOST... (2 Replies)
In my program, threads may be created when some events trigger. So I can't create threads on initialization.
Theremore,I write a createThread() function to create thread. However, it is blocking at first call and don't run anymore? why?
#include <pthread.h>
#include <stdio.h>
#include... (4 Replies)
Hi All,
I want to get %cpu and %memory utilization for a given process id in HP-UX so am using the following commands
1)TOP -p <PID> am getting error message like Quitting top: pset 26323 doesn't exist,but when am using only TOP command without any options its working fine.
2)ps -e -o pcpu... (5 Replies)
Hi All,
I m not able to run at job with normal user on AIX system
os version is 5300-05-06.
I am able to run at job only with root user.
When I try to run at job with any other user I am getting error:
at: you are not authorized to use at. Sorry.
I checked at.deny file, it is... (4 Replies)
Hi Guys,
I am unable to return a decimal value from a function to the main script.
I am getting the correct value in the function but when it is returning to the main script using "return" it is coming as 0. Below is my code.
read VALUE_V fun_FATHERID fun_SONID fun_TOPID fun_RTYPE <... (2 Replies)
I have a script A which calls script B. I wrote a function in script A to be executed when Kill command is issued for script A and I invoke that function using the trap command.The function identifies all child process running under script A (in this case script B) and kills the child process and... (3 Replies)
Hello.
I am trying to run xclock on newly built solaris box - These are the steps I followed:
# DISPLAY=localhost:0.0
# export DISPLAY
# xclock
xclock: not found
# cd /usr/openwin/bin
# ./xclock
Error: Can't open display: localhost:0.0
#
Please suggest, what am i doing wrong?
Thank... (27 Replies)