Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Determine a script's execution dir?
Name: tshea Date: February 12, 2005 at 07:37:53 Pacific OS: HP-UX 11 CPU/Ram: PA-RISC / 1GB
Comment:
I have a script that has to record it's actions in a log file. I'd like to ensure that it always writes to a log file that is in the same directory as the script.
I tried to establish the name of the log using the dirname & basename cmds: LOGFILE=`dirname $0`/`basename $0 .sh`.log This works as long as the script is run using an absolute path. If I run /scripts/test.sh , my LOGFILE variable is set to /scripts/test.log.
If the script is run using a relative path, cd /scripts test.sh the LOGFILE variable gets set to ./test.log. The script changes directories during execution resulting in it writing to test.log in whatever the current working directory is.
I think I need to find a replacement for the dirname command that always returns an absolute path. I have tried a which test.sh command but that also can return a relative path name.
Name: vgersh99 Date: February 12, 2005 at 09:08:26 Pacific
Reply:
if you're using 'ksh', you can do 'whence $0' at the beginning of the script to give you the path to the script itself. From there you can derive the path AND the script name.
Summary: Hi, I got a script that execute a command like this : et -A array_name `ps -ef | grep -i $process_name | grep -v 'grep' | grep -v 'kill' |grep -v $0| sort|awk '{print $2}' | sort -u` this is bloody lo...
Summary: I want to make an alias where in I want to rlogin to a server and execute a scipt with it..I tried the command (alias KP "rlogin 10.180.10.23 -l kamal ; konsole") KP is alias name 10.180.10.23 is the ...
Summary: I am trying to troubleshoot a problem that I am having with a script. The problem appears to be in a function within the script. When I use ksh -x scriptname, I can see the call that is made to my f...