Operating System - HP-UX
1825645 Members
3872 Online
109685 Solutions
New Discussion

How to auto start a script which required csh enviroment

 
SOLVED
Go to solution
Ervin Liu
Occasional Contributor

How to auto start a script which required csh enviroment

I have a bourne shell script which is required to be executed in csh.Now, I need to run this script every time when system boot up.I want to embed following command in my start script(/sbin/init.d/..)" su - username -c "csh -c scriptname" >/dev/null 2>&1 " .I am not sure if it is good solution.I would appreciate it very much if you can give me some suggestion.

thanks
10 REPLIES 10
Carlos Fernandez Riera
Honored Contributor

Re: How to auto start a script which required csh enviroment

TO force execution of csh include in the first line of your script:
#!/usr/bin/csh
unsupported
Dan Hetzel
Honored Contributor

Re: How to auto start a script which required csh enviroment

Hi Ervin,

Scripts in /sbin/init.d (or /sbin/rc?.d) will execute independently of their respective shells.
Simply make sure that the first line of your script reads:
#!/usr/bin/csh
if you want a csh to interpret the script.

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Sandor Horvath_2
Valued Contributor

Re: How to auto start a script which required csh enviroment

Hi !

What You wrote it is correct if Your script's first line is good. But You can run it only when mounted /usr filesystem where You find csh. Don't forget it !

regards, Saa.
If no problem, don't fixed it.
Dan Hetzel
Honored Contributor

Re: How to auto start a script which required csh enviroment

Good point, Sandor !!
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Ervin Liu
Occasional Contributor

Re: How to auto start a script which required csh enviroment

Carlos and dan
Thank you for you suggestion.Do you mean in my start script,let's say /sbin/init.d/my_startscript,I put the first line to
#!/usr/bin/csh.?
I think it should be good solution.But I still want to confirm it.so let me explain the complete case.
The user is called "user1",his default login shell is "/usr/bin/sh".He configured some customrized parameter in /home/user1/.cshrc. Every time when he try to run his bourne shell script "user1_script",he do "csh;user_script".I think the reason that he run "csh" command is that he want to execute /home/user1/.cshrc.I read the user_script,I did not see any relation between user_script and .cshrc.I don't know why user must run csh first,then start his user_script.Anyway,I just want my auto_start script match his procedure.
So do you think that I put the #!/usr/bin/csh in the first line of my start script,which can execute .cshrc and match this user's procedure?
thanks again

Bruce Regittko_1
Esteemed Contributor

Re: How to auto start a script which required csh enviroment

Hi,

Yes, the #!/usr/bin/csh line will cause the rest of the script to be executed by the c shell.

Make sure the #! are the absolute first two characters of the file - no indentation or blank lines above. Otherwise, the line will just be a comment and the script will most likely run under the POSIX shell.

--Bruce
www.stratech.com/training
Dan Hetzel
Honored Contributor
Solution

Re: How to auto start a script which required csh enviroment

Hi Ervin,

That's it! If your script starts with the following line (without any indentation or space before):
#!/usr/bin/csh
and that, at that time, /usr is mounted, C-shell will be used to interpret the script.

Nevertheless, the file /home/user1/.cshrc won't be run because there is no relation with scripts in /sbin/rc?.d or /sbin/init.d and a user directory.

You can explicitely force that file to be read by putting this line in the script (i.e. as second line):
source /home/user1/.cshrc

Make sure that the /home/user1/.cshrc doesn't use any terminal related command (like echo, tset...) as there won't be any terminal attached to the process at run time.

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Dan Hetzel
Honored Contributor

Re: How to auto start a script which required csh enviroment

Ervin,

Another point to keep in mind:
Scripts in /sbin/init.d run as 'root', so make sure this is what you want to do.
Otherwise, your script should contain a line like 'su user1 -c ' if it needs to be run with another user ID.

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Ervin Liu
Occasional Contributor

Re: How to auto start a script which required csh enviroment

HI Dan
I got it.Thank you for your excellent guide.

regards
ervin
Dan Hetzel
Honored Contributor

Re: How to auto start a script which required csh enviroment

You're welcome !
Thanks for the points.

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com