Can't run /bin/bash... sometimes?

1

I’m on a Google Compute Engine which is running Debian Wheezy 7.4.

I’ve been noticing strange things recently. For example, I can do sudo bash. But then, from root, I can’t do sudo -u anotherUser bash or su -l anotheruser -c bash.

And, even more importantly, I can’t start new instances of GNU screen. If I try starting a new instance, it immediately shuts down and I get the [screen is terminating] message. In the instances that were running, I could not start more windows.

Then I found what all had in common: bash!

I can do screen zsh or screen sh.

I can do sudo bash and then sudo -u anotheruser zsh or su -l anotheruser -s zsh but NOT su -l anotheruser -c zsh.

Note that I am logging in with bash and I can do sudo bash. But I can't use bash for sudo or su from root to another user, nor can I use bash for a screen shell.

I rebooted. Yes, this worried me so much I actually rebooted my server.

I have no idea what can cause this and I'm a bit worried.

My bash config files (as for as I know they are unchanged from default):

bash completion works on the main (login) shell.

Here is the information requested by Glenn Jackman:

$ md5sum /bin/bash /usr/bin/bash
144968564a6b1159ed82059920cea76f  /bin/bash
md5sum: /usr/bin/bash: No such file or directory
$ getent passwd anotheruser
anotheruser:x:1004:1004::/home/anotheruser:/bin/bash

Also I thought of another test. This works:

$ echo $(bash -c 'echo Hello, World!')

What's going on?

eje211

Posted 2015-02-19T03:59:27.333

Reputation: 229

What do these return: md5sum /usr/bin/bash /bin/bash and getent passwd anotheruser ?? – glenn jackman – 2015-02-19T05:05:11.643

I'll add those to the main body of the question. I still think some profile files are to blame. It's the only thing that makes sense to me. – eje211 – 2015-02-19T18:00:58.547

Answers

0

There was a problem in:

/usr/share/bash-completion/bash_completion

More specifically, it is the line at the beginning:

if [ "$0" != "-bash" ]; then exit; fi

That line checks if the current shell is bash. If it's not, it does not use bash completion. If I remove the line, I get errors in some scripts that try to use the [[ command.

This is what I came up with in the end:

isbash=no
case "$SHELL" in
  *bash*) isbash=yes ;;
esac
case "$0" in
  *bash*) isbash=yes ;;
esac
if [ "$isbash" = "no" ]; then exit; fi

eje211

Posted 2015-02-19T03:59:27.333

Reputation: 229

Please mark this as answered if you have answered your own question. – Jared Burrows – 2015-02-19T20:05:34.780

Silly rule, right? But ok. – Jared Burrows – 2015-02-19T21:41:11.540