Linux – Running tcsh scripts on startup in bash env

bashlinuxshell

I have a user called foo which is using tcsh by default in /etc/passwd. I cannot change that default shell. Foo has a service called xyz running, for which all the startup scripts and .(dot) file containing ENV variables are in home dir of foo.

Now a startup script is also created to run that service and placed in /etc/init.d/xyz which is written in bash.

Now the issue is that the service is not starting on boot and I cannot run it from my default user on login too. It is only possible to run when I su into foo user and execute the script to start the service.

If I do like this

sudo su foo /home/foo/xyz it will show me errors like then: then/endif not found..

So what I want to run a tcsh program to run on boot from a init.d script which is in bash. At present I tried to do this

su - foo -c "source /home/foo/.env_vars && /home/foo/bin/xyz start" but this is not starting the service at the time of boot.

I am not sure how to make a tcsh script execute on boot time.

Best Answer

You can either:

  • use tcsh -c $script to run the scripts with tcsh
  • set the shebang (first line) in the script to #!/bin/tcsh and set it executable; you can then just start it with $script as the command.