Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling the cshell profile from kshell in cron jobs

Posted on 2006-10-31
15
Medium Priority
?
607 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:gvsunil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +3
15 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 1400 total points
ID: 17843430
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
 

Author Comment

by:gvsunil
ID: 17843453
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
 
LVL 58

Expert Comment

by:amit_g
ID: 17843488
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 17843617

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

0
 

Author Comment

by:gvsunil
ID: 17844830
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
 
LVL 58

Expert Comment

by:amit_g
ID: 17844871
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
 

Author Comment

by:gvsunil
ID: 17845176
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
 
LVL 58

Expert Comment

by:amit_g
ID: 17845211
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
 
LVL 48

Expert Comment

by:Tintin
ID: 17845510
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
 

Author Comment

by:gvsunil
ID: 17846185
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
 

Author Comment

by:gvsunil
ID: 17846244
Also please note that our default shell is cshell.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 200 total points
ID: 17846325
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
 
LVL 58

Expert Comment

by:amit_g
ID: 17846328
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
 
LVL 38

Expert Comment

by:yuzh
ID: 17846986
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
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 400 total points
ID: 17874382
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question