Bash: cannot set terminal process group (-1): Inappropriate ioctl for device

bashlfssourcesuUbuntu

Trying to execute the source command using "lfs" user on ubuntu 14.04 and getting this:

root@linux:~/lfs# su lfs - -c "source ~/.bash_profile"
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell

Any ideas?

Background info: I am following the LFS book, making a script out of it, so in my script which I execute with sudo, when it gets to this part, after creating the lfs user and his .bashrc and .bashprofile, I guess it is loading it.

Context:

echo "info: create 'lfs' group and user..."
groupadd -f lfs
id -u lfs &>/dev/null || useradd -s /bin/bash -g lfs -m -k /dev/null lfs
passwd -d -q lfs

echo "info: make 'lfs' own the 'tools' and 'sources' directories..."
chown lfs $LFS/tools
chown lfs $LFS/sources

echo "info: creating a clean '.bash_profile' as user 'lfs'..."
su lfs - -c "cat > ~/.bash_profile << \"EOF\"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF"

echo "info: creating a clean '.bashrc' as user 'lfs'..."
su lfs - -c "cat > ~/.bashrc << \"EOF\"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
LFS_TGT=$(uname -m)-lfs-linux-gnu
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL LFS_TGT PATH
EOF"

su lfs - -c "source ~/.bash_profile"

Edit:

It has been suggested that my syntax is incorrect, I am not at my linux machine at the moment, so will try to use different syntax when I get the chance. However, for info, I got the syntax from the answer here: https://serverfault.com/questions/411307/cannot-set-terminal-process-group-during-su-to-another-user-as-login-shell

Best Answer

  • su - username runs the login shell of username as an interactive shell.

  • su username command arguments runs command arguments non-interactively under the account username.

You command su lfs - -c "source ~/.bash_profile" means run - -c "source ~/.bash_profile" as the user lfs non-interactively. Now the shell sees the option - and says, I am to run as an interative login shell, and tries to initialize the terminal, but su has disconnected the child process from the controlling terminal.

In short: The - is either misplaced or erroneous.

For a longer discussion, see practically the the same question on serverfault.

Related Question