gvsunil
asked on
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
eval ~/.cshrc
exit
Any comments will help on this command ?
Thanks
GVS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
#!/bin/csh
#Wrapper CShell Script
source /home/user1/.cshrc
YourKShellScript
In YourKShellScript make sure to have
#!/bin/ksh
Schedule Wrapper CShell Script in cron.
-- OR -- Just convert .cshrc to ksh and avoid headaches.
ASKER
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
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
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.
ASKER
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
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
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
#!/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
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.
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.
ASKER
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
#!/bin/ksh
env
test="/usr/bin/csh -c 'source ~/.cshrc'"
# Kshell script goes here..
env
Thanks
GVS
ASKER
Also please note that our default shell is cshell.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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