0

following problem. I got this shell script:

#!/bin/sh

# Provide log for debugging
if [ ! -f /home/some-user/port-control.log ]; then
  touch /home/some-user/port-control.log
  chown some-user /home/some-user/port-control.log
fi

# Load environment variables for authentication
source /home/some-user/.openstack/nova-openrc.sh

# Open ports at login
if [ "$PAM_TYPE" = "open_session" ] && [ "$PAM_USER" = "some-user" ]; then
  echo "Opening ports ... Nova response:" >> /home/some-user/port-control.log
  nova --debug add-secgroup some-server some-secgroup &>> /home/some-user/port-control.log
fi

# Close ports at logout
if [ "$PAM_TYPE" = "close_session" ] && [ "$PAM_USER" = "some-user" ]; then
  echo "Closing ports ... Nova response:" >> /home/some-user/port-control.log
  nova --debug remove-secgroup some-server some-secgroup &>> /home/some-user/port-control.log
fi

I'm using this script to open/close some ports in my firewall when connecting/disconnecting via ssh by dynamically adding an already configured secgroup to my server - at least thats the idea. Unfortunately, the nova commands somehow don't seem to execute at all, I get nothing in my log. Now, since I got no stderr, debugging is kinda hard. What am I doing wrong?

When I source the nova login credentials and execute the nova commands manually outside a script, everything works perfectly fine.

Btw: If it helps: I'm running all this inside a docker container based on an Ubuntu:14.04 image. Yeah, I know: If you're using sshd inside a docker container, your doing it wrong. In this case, there's a reason for the sshd ;)

1 Answer 1

0

Somehow simple, but finally I found the answer. This is what I did:

With the help of an answer to another question at StackOverflow I redirected the whole output of the script to a file and realized that the environment variables for authentication didn't get sourced. Why: Because the shell didn't know the source command. Why? Because I was stupid enough not to check witch shell I was using.

The problem was simply fixed by changing #/bin/sh to #!/bin/bash. Tada!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .