Operating System - HP-UX
1747992 Members
4840 Online
108756 Solutions
New Discussion юеВ

Re: how to implement script command in a .cshrc ( csh)

 
sstan
Frequent Advisor

how to implement script command in a .cshrc ( csh)

hi,
i encounter error when try to implemented a script command in a .cshrc file.

the line i added in .cshrc is :

set tstamp=(`date +%d%m%Y-%H%M%S`)
set fscript=/sgx/core/tslog/log-$tstamp
script $fscript
#echo $tstamp

Is the way doing is wrong for .cshrc ? any help is appreaciate. i canot figure what went wrong.

attached the 1st part of the .cshrc contents and the next part separated by line is the error shown when i login as the particular user .cshrc profile
24 REPLIES 24
Patrick Wallek
Honored Contributor

Re: how to implement script command in a .cshrc ( csh)

Why anyone would willingly use the c shell is a mystery to me. Anyway, try this:

setenv tstamp `date +%d%m%Y-%H%M%S`
setenv fscript /sgx/core/tslog/log-$tstamp
script $fscript
Patrick Wallek
Honored Contributor

Re: how to implement script command in a .cshrc ( csh)

After looking at your attachment, I'm confused.

Did you just log into the system as a regular user when the output was generated? I'm not sure why you get the multiple iterations of the script command.
sstan
Frequent Advisor

Re: how to implement script command in a .cshrc ( csh)

hi Patrick,
csh was used because legacy, then can the user variable assigned using the setenv?

I as a root user, then i do su - user and run the .cshrc and get the script command running repeately. i am wonder why ? also some error
Warning: ridiculously long PATH truncated

any idea ?
i try your method it still don't work.
OldSchool
Honored Contributor

Re: how to implement script command in a .cshrc ( csh)

ok, when you start a csh, it runs .cshrc. when your .cshrc runs, the "script" command starts a new shell (either /usr/bin/sh or the contents of $SHELL if avail). In your case, $SHELL /usr/bin/csh. You haven't completed your login, so the new csh runs .cshrc which starts a new shell which runs .cshr which......

PATH keeps getting added to, no logins get finished, and so on.

Still not sure why you'd want to use csh. I'm not sure what you mean by "Its legacy"
OldSchool
Honored Contributor

Re: how to implement script command in a .cshrc ( csh)

BTW, it tried the above in csh and its doing exactly as I described, altough it appears to function as desired in either ksh or sh.

note that if you do something like this in the other shells, the command immediately after the "script" command needs to be "exit", otherwise the user will remain logged in after they type exit the first time (and logging to the file will be shut off)
sstan
Frequent Advisor

Re: how to implement script command in a .cshrc ( csh)

hi patrick,
the script in .cshrc is seems working, but i noted a strange behaviour. When the 3 new added line executed, the alias ( shortcut ) in .cshrc missing when i do a su - user .

later when i type exit command it come back to the csh prompt with alias take effect ?

How to explain on this ? strange.
any advise is appreaciate.
bin is a shorcut to a path /sgx/core/bin

for e.g
$ pwd
/sgx/login/coreadm/RUN
$ bin
sh: bin: Execute permission denied.
$ exit
Script done, file is /sgx/core/tslog/log-01112007-033355
[~/RUN ](21)
[~/RUN ](21) bin
[/sgx/core/bin ](22)
OldSchool
Honored Contributor

Re: how to implement script command in a .cshrc ( csh)

from csh man page regarding command line switches:

-i Force csh to respond interactively when called from a device other than a computer terminal (such as another computer). csh normally responds non-interactively. If csh is called from a computer terminal, it always responds interactively, regardless of which options are selected.

note the part about "runs interactively". this implies that the .cshrc will always be run, so you are basically recursing.
sstan
Frequent Advisor

Re: how to implement script command in a .cshrc ( csh)

Hi OldSchool,

strange problem is when i su - username run the .cshrc ,
it say :

Script started, file is /sgx/core/tslog/log-01112007-035155
$

normally when user login it should show this type of prompt.
[~/RUN ](21)

BUT the csh prompt suppose to show is gone, and only when i type exit it return back and all alias is back to effect, how to overcome this problem. i try to put a exit after the script command , it show same symptom.

any advise is appreaciate. for e.g
bin is a shorcut to a path /sgx/core/bin

$ pwd
/sgx/login/coreadm/RUN
$ bin
sh: bin: Execute permission denied.
$ exit
Script done, file is /sgx/core/tslog/log-01112007-033355
[~/RUN ](21)
[~/RUN ](21) bin
[/sgx/core/bin ](22)
OldSchool
Honored Contributor

Re: how to implement script command in a .cshrc ( csh)

What I'm saying is:
A) I wouldn't / don't expect this to ever work as you want in csh.
B) It will work as desired if you change the users shell to either sh (POSIX) or sh
C) If you do B, then but "exit" after script in the users ".profile"