Solved

Calling the cshell profile from kshell in cron jobs

Posted on 2006-10-31
15
593 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
  • 5
  • 5
  • 2
  • +3
15 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 350 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 29

Expert Comment

by:MikeOM_DBA
Comment Utility

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

0
 

Author Comment

by:gvsunil
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 58

Expert Comment

by:amit_g
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Also please note that our default shell is cshell.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 100 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now