start up script

Hi all,

can someone please answer few questions on shell scripts and some basic setup.

I have the below script to load geli devices, import zpool, and restart samba, then I want to start syncthing. Right now I have two scripts, one for geli and zpool, executed by root, then syncthing script executed by user "tango".

first, is it possible to run all this without the root privileges?
Then I can merge these two scripts.

This script is run as root:
Code:
###############
#!/bin/csh -f
# attach geli containers

geli attach /dev/label/dataE0

  if ($status == 0) then

  geli attach /dev/label/dataE1

  if ($status == 0) then

  # import zpool tank3 (on a 2-way mirror)

  zpool import tank3

  # mount zfs datasets from tank3

  zfs mount -a

  #start samba

  service samba_server restart

  else

  geli detach /dev/label/dataE0.eli

  echo detached dataE0.eli

  echo failed to attach dataE1.eli, check your password.

  endif

  else

  echo failed to attach dataE0.eli, check your password

  endif
###################

then I run the below script to launch syncthing by user "tango"

Code:
###############
#!/bin/csh -f

set stamp = `date -j +%Y%m%d%H%M`

nohup /usr/home/tango/syncthing/syncthing -no-browser -logfile="st$stamp.log" -logflags="3"  
###############

also what is the default shell?
for root, env returns csh and for user it is sh?
I don't remember making any specific changes to the shell choice.

also I have a .cshalias file with some aliases for the root shell. How to use the same file for all users/shell environments, I dont want to maintain different alias files.

I also want to minimize the use of root user account for routine maintenance, right now to even shutdown/reboot, update packages, etc, need root privileges, is it possible to give the main user account (tango) the privileges needed to do these routine chores?

thank you.
yudi
 
Don't use csh(1) for scripts, this will only lead to frustration. The csh(1) shells are great for interactive use but terrible for scripting. For scripts use sh(1), or for more complicated scripts Perl, Python or Ruby.
 
Don't use csh(1) for scripts, this will only lead to frustration. The csh(1) shells are great for interactive use but terrible for scripting. For scripts use sh(1), or for more complicated scripts Perl, Python or Ruby.

I agree, it was annoying that I had to learn csh scripting, I did not get why csh was the default. I was used to bash and hoped it would be the default but not! I am fairly new to FreeBSD and assumed only csh was available until I noticed bash was set as default for normal user.
 
Last edited by a moderator:
I agree, it was annoying that I had to learn CSH scripting, I did not get why CSH was the default. I was used to BASH and hoped it would be the default but not! I am fairly new to freebsd and assumed only CSH was available until I noticed BASH was set as default for normal user.

It is not bash mind you, it's a derivative of Almquist's Shell and is quite stripped down compared to for example shells/bash or shells/zsh.

https://en.wikipedia.org/wiki/Almquist_shell
 
Yes, contrary to a lot of Linux distributions on FreeBSD /bin/sh is NOT a limited Bash. The reason the default shells don't include Bash is because it's not part of the base OS.

For user accounts I can recommend setting the shell to tcsh. Bash can also be used but will need to be installed separately. Do not change root's shell to /usr/local/bin/bash, it may cause problems when you update/upgrade the system and will prevent you from logging in.

But, even with a user's shell set to Bash, try to write scripts using /bin/sh, not /usr/local/bin/bash.
 
It is not bash mind you, it's a derivative of Almquist's Shell and is quite stripped down compared to for example shells/bash or shells/zsh.
Thanks for clarifying.
All these different shells, what a headache. Why don't they just have one shell as default and consistent. If csh (or is it tcsh, wiki says tcsh is the default for FreeBSD) is preferred then why is user shell set to /bin/sh?
Once I get the aliases and rc file setup and those couple of scripts to automate the tasks, I probably will never have to worry about the shell setup. This is on a backup server, once setup, there will be minimal day-to-day admin.

For user accounts I can recommend setting the shell to tcsh. Bash can also be used but will need to be installed separately. Do not change root's shell to /usr/local/bin/bash, it may cause problems when you update/upgrade the system and will prevent you from logging in.

I will not bother with installing bash, will stick with csh/tcsh.
So I can safely change the user shell to tcsh?
up until now I have been reading up on csh, should I have learnt tcsh?
 
Last edited by a moderator:
so I can safely change the user shell to TCSH?
Definitely. I always use tcsh(1) for my own accounts (even on Linux systems).

up until now I have been reading up on csh, should I have learnt tcsh?
They're actually the same. On Linux sh is often bash running in a compatibility mode. FreeBSD has a similar thing, tcsh(1) and csh(1) are the same executable but starting it as csh(1) uses a similar compatibly mode (it basically disables the "new" features of tcsh(1)).
 
Back
Top