Calling the cshell profile from kshell in cron jobs

We are trying to execute a kshell script and wanted to execute the cshell profile. We tried to use the following command and it did not work .

eval ~/.cshrc
exit

Any comments will help on this command ?

Thanks
GVS
gvsunilAsked:
Who is Participating?
 
amit_gConnect With a Mentor Commented:
Why not execute the cron job in the cshell instead? Just put the

#!/bin/csh

as the first line in your script that is going to be executed by cron and then you can do

source /home/user1/.cshrc

and have rest of the script after it.
0
 
gvsunilAuthor Commented:
Amit,

All of our scripts are in KSHELL so we were trying to run all of the scripts in Kshell prompt. So is there a way to call and execute the cshell profile from Ksh ?

Thanks
GVS
0
 
amit_gCommented:
Both shells have different syntax so I doubt that it be possible. Are you exporting all variables from .cshrc? If so you could try a wrapper. Make a script like

#!/bin/csh
#Wrapper CShell Script
source /home/user1/.cshrc
YourKShellScript

In YourKShellScript make sure to have
#!/bin/ksh

Schedule Wrapper CShell Script in cron.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
MikeOM_DBACommented:

-- OR -- Just convert .cshrc to ksh and avoid headaches.

0
 
gvsunilAuthor Commented:
Amit,

I agree, that converting the .cshrc might be easy, but our default shell is cshell, so if we convert other scripts might get effected right ?

Also do we need to have a separate wrapper script and what it contains ?

Thanks
GVS
0
 
amit_gCommented:
Try the one given in http:#17843488 The wrapper script is nothing but a 2 line cshell script that sets the environment and invokes the kshell script. You will have to make sure that the variables in .cshrc are exported. Try it with one and if it works, you could modify it to take an argument and based on that argument it can run different kshell scripts. That way you would need only one wrapper cshell script.
0
 
gvsunilAuthor Commented:
Amit,

Based on my understanding, I modified the existing  kshell script as follows:

#!/bin/csh
#Wrapper CShell Script
source ~/.cshrc
#!/bin/ksh
# From here onwards my kshell script.......

Is this correct ? I will export the variables in .cshrc and try running this .

Thanks
GVS
0
 
amit_gCommented:
No not this way. Lets say you have a kshellscript named as KShellScriptName.sh. Create a new script say CShellSrapper.sh and have this in it

#!/bin/csh
#Wrapper CShell Script
source ~/.cshrc
KShellScriptName.sh

and in KShellScriptName.sh make sure that the first line is

#!/bin/ksh

Also check if the path /bin/csh and /bin/ksh are correct. If not use the correct path as per your system. You can find the correct path using

which ksh
which csh
0
 
TintinCommented:
Does the .cshrc have many lines?

The easiest way would be to have

~/.cshrc

and

~/.kshrc

With the csh environment in .cshrc and the equivalent setup in .kshrc for korn shell.
0
 
gvsunilAuthor Commented:
Yes, .cshrc has many lines and we were trying to persue the following command as well in kshell to source the cshell variables , but when we try to run this as a script, this is not storing the variables of .cshrc and getting syntax errors.

#!/bin/ksh
env
test="/usr/bin/csh -c 'source ~/.cshrc'"

# Kshell script goes here..

env

Thanks
GVS
0
 
gvsunilAuthor Commented:
Also please note that our default shell is cshell.
0
 
TintinConnect With a Mentor Commented:
What *specifically* do you need from the .cshrc file?

You can't do

test="/usr/bin/csh -c 'source ~/.cshrc'"

as source is a csh builtin, not a command and even if source was a command, that assignment wouldn't do anything useful for you.

The way to go is either use the approach as mentioned by amit_g, or tell us exactly what the ksh scripts are reliant on in the .cshrc file.
0
 
amit_gCommented:
You won't be able to call a cshell script (.cshrc) from a kshell script. You could try a cshell wrapper that sets the env and then calls the kshell script. There could be some issues with that too but that is probably the closest you could get to it other than translating .cshrc to kshell syntax.
0
 
yuzhCommented:
Why you want to use csh ENV seetings from ksh?

Bad news is that, it is not going to work for you, since the shell syntax are very different between the 2 shells.

If you  want to use a user's login ENV setting (with csh as the default login shell) to run
a csh scrtpt, you can do:

su - cshuser -c /pathto-/mycshscript

it should not ask any password if you run the cron job as root.
0
 
ahoffmannConnect With a Mentor Commented:
rule #1: you cannot call (source) .cshrc within ksh
rule #2: you cannot call (.) .kshrc from within csh
rule #3: AFAIC there exist no convertion programs in either direction

if you have a simple .cshrc you can write a simple wrapper to evaluate in ksh

I'd simply write a cshell wrapper which you call in your cron:

#!/bin/csh
source ~/.cshrc
/full/path/to/your.ksh
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.