All Forums |
Register |
Login |
Search |
Subscriptions |
My Profile |
Inbox |
Tool Warehouse |
FAQs |
Resources |
Help |
Member List |
Address Book |
Logout |
|
|
script file system behavior
|
Logged in as: Guest |
Users viewing this topic: none |
|
Login |
|
|
script file system behavior - Jun. 18, '06, 1:16:09 AM
|
|
|
dsquared
Posts: 6
Joined: Jun. 18, '06,
Status: offline
|
Hi,
I'm a long time UNIX user and have been "tasked" with converting some UNIX scripts to run in the XP environment. I've installed SFU 3.5 and in the process of executing scripts I've noticed the unhappy behavior that when the script starts executing it does not remember the directory where it was started, i.e. as others have noted it starts off in my PC "home" directory. This is not at all how scripts behave when executed in a real UNIX environment. I ASSUME there must be some way to have the script either determine where it was initiated or to somehow feed it that information. Can anyone out there give me a clue?
Thanks for your help.
Don Durschmidt
|
|
|
RE: script file system behavior - Jun. 18, '06, 2:17:38 AM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
The "problem" is most likely how you start the scripts.
I live in the Interix environment virtually 100% of the time (i.e. not Win32) and
never see the behavior that you describe. I start all scripts from an Interix shell
(or from at least an Interix process such as the cron daemon). Since Interix is
a Unix environment everything works as expected on other Unix systems because I stay
in that environment. It becomes "just another Unix system".
If you start a script from a Win32 environment then things change. You are starting
a Unix script from a Win32 environment. There is a transition from one environment
to another. The transition is initially starting a shell to run the script. Since
this shell is not started from within the Interix/Unix environment some base info
needs to be set. If the shell is started as a login shell then this set info as
a login to the Interix/unix environment would. A login will clobber old info. This
happens on all Unix systems. It's just you can't really see what was there before.
If you start the shell as a non-login shell then information from the previous
environment will survive (though it may still exist in Win32-speak), but other
base information will be missing (because it is normally only added as part of a
complete login). If you could login to a Unix system without doing all of the login
procedure (which you can't) then you could get a similar situation.
The transition from one environment to another is a unique aspect that is
not grasped easily because it is so unusual to have faced it before.
So how are you starting the scripts?
|
|
|
RE: script file system behavior - Jun. 19, '06, 9:51:28 AM
|
|
|
dsquared
Posts: 6
Joined: Jun. 18, '06,
Status: offline
|
I am intending to try two ways, the two ways my user community will probably use. So far, I have only started the execution from a DOS window which was navigated to the proper directory. I would also like to see how the script acts if it is double clicked from an Explorer window. Any hope for me to have it behave as I'd like?
|
|
|
RE: script file system behavior - Jun. 19, '06, 1:36:56 PM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
Details are required.
What exactly is the command line you are using to start the script?
|
|
|
RE: script file system behavior - Jun. 19, '06, 1:49:26 PM
|
|
|
dsquared
Posts: 6
Joined: Jun. 18, '06,
Status: offline
|
Well, I have mounted a UNIX directory which is where the actual script resides. In my Environment Variables, I have added the directory where the script resides, F:\bin at the beginning so it is searched first. The name of the script is ids_batch.ksh and I give it one argument, an input file name. So from my DOS window, which is in the directory where I want the execution to occur, I type:
ids_batch.ksh Test_in_101
By the way, I really appreciate your help Rodney. I have managed through trial and much error, to get the script to do everything else I want it to do as it does on UNIX. I just need to get it the information about the directory where I want it to execute.
|
|
|
RE: script file system behavior - Jun. 19, '06, 1:53:35 PM
|
|
|
dsquared
Posts: 6
Joined: Jun. 18, '06,
Status: offline
|
... with one caveat, I have not found an equivalent of the "timex" command in Interix. We have used it on both HP/UX and AIX to get the command execution times for the program we are running. Might you know of a way to get the execution times from Interix??
Thanks again.
|
|
|
RE: script file system behavior - Jun. 19, '06, 4:19:59 PM
|
|
|
markfunk
Posts: 673
Joined: Mar. 31, '03,
Status: offline
|
Your problem is that you are expecting UNIX behaviour from the Win32 environment.
That is an invalid expectation. These are two very different subsystems.
You cannot arbitrarily execute UNIX shell scripts from the Win32 environment and expect
to see full UNIX behaviour.
There is a transition that must occur when executing UNIX utils from Win32 and vice versa.
To meet your expections, you must start/execute your shell script from an Interix shell.
What's happening for you now:
When you execute your .ksh script from the cmd.exe prompt in a DOS window,
it is cmd.exe that looks up the associated program that should execute your script.
On your system, you can figure this out by typing "ftype KornShellScript" in a cmd.exe DOS window.
You will notice that it is invoking "...\SFU\bin\ksh -l ..."
which will do two things:
a) the Interix environment subsystem will be called, which does some environment variable
changes to properly transition you from the Win32 world to the UNIX/Interix world
b) start up the ksh logon shell. Which sets a bunch more env. variables (see /etc/profile)
and changes the current directory to the value in $HOME env. variable.
This is why your script is being run in your home directory and not the current directory.
|
|
|
RE: script file system behavior - Jun. 19, '06, 4:53:14 PM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
> ... with one caveat, I have not found an equivalent of the "timex" command in Interix.
From a csh or kshyou would "% time <program> <args ...>".
That'll do it with the csh built-in to the shell.
Close as you'll get right.
|
|
|
RE: script file system behavior - Jun. 19, '06, 5:10:14 PM
|
|
|
dsquared
Posts: 6
Joined: Jun. 18, '06,
Status: offline
|
Rodney,
How do you "live in the Interix environment?" I.e what command, aside from executing a unix script in a DOS window, puts you there? I guess that is really the answer to my question if invoking a script is really the equivalent of a login in terms of the directory I am in. Is it possible to start a script as something other than a "login shell?"
|
|
|
RE: script file system behavior - Jun. 19, '06, 5:13:40 PM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
To follow through after Mark's comments and tie them to one of your earlier ones.
The "-l" is what tells ksh that it is to act like a login shell. The
same is true for csh/tcsh, zsh, bash, ...
Most folks using Unix are just unaware that this happens.
The shells to start in the Start Menu are shortcuts. You can copy these shortcuts
to the desktop (or wherever). You can then edit the shortcut (Properties popup)
to your own designs. This would include adjusting the command line in the shortcut
to ask ksh to start your script, but without the '-l' (no login).
Refer to the ksh man page for info on args "-c" and "-l".
|
|
|
RE: script file system behavior - Jun. 19, '06, 5:32:31 PM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
> How do you "live in the Interix environment?"
I start several csh (actually it's tcsh really).
Start them up from either the Start Menu or a Desktop shortcut I've made.
I treat the Win32 desktop just as another desktop window manager, just
as I would on another box using an X server. Of course I can start an X server
as well and open several xterm's or rxvt's instead.
Then I telnet and ssh around. Edit using vi, search
for things using find and grep. I don't use CMD.EXE or Wordpad.
There are some Win32 commands that I occationally run, but I can do this
from within the Interix environment.
|
|
|
RE: script file system behavior - Jun. 20, '06, 9:28:43 AM
|
|
|
markfunk
Posts: 673
Joined: Mar. 31, '03,
Status: offline
|
Is it possible to start a script as something other than a "login shell?"
Yes. You can either remove the "-l" in the KornShellScript association
or you can invoke the ksh.bat script that's located in %SFUDIR%\common\ksh.bat.
Such as "ksh.bat ids_batch.ksh"
Just remember that you have not started a "logon" shell and thus,
some env. variables may not be set correctly for the UNIX/Interix environment.
(like TMPDIR, PATH, LD_LIBRARY_PATH, TERM, EDITOR, ....)
|
|
|
RE: script file system behavior - Jun. 20, '06, 2:41:26 PM
|
|
|
dsquared
Posts: 6
Joined: Jun. 18, '06,
Status: offline
|
Gentlemen,
I sincerely thank you for your assistance. I believe I am on the straight and narrow path now.
|
|
|
[Deleted] - Aug. 23, '06, 10:51:00 AM
|
|
|
jameskobe1
|
Post has been moved to the Recycle Bin at Aug. 23, '06, 1:41:54 PM by Rodney
Reason for deletion: spam
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
|
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|
|