Monday, November 02, 2009

SSH Works, SCP/SFTP Fails? Check all login scripts

Gaah! Some fool snuck an unconditional echo statement in a global profile. Surefire way to get scp and sftp to stop working. Lines that produce output, or exec statements should be conditionally placed in shell startup scripts. It's best not to have these lines take effect for non-interactive shells. I like to test "$0" to see if it begins with a '-' to determine if a shell is a login shell, and process the rest of the script accordingly. In bash:
case $0 in
-*) # Login shell
    ;;
 *) # non-interactive shell
    ;;
esac
In csh:
switch ($0)
       case -*:
          # login shell stuff

          breaksw
       default:
          # non-interactive stuff
          breaksw
endsw

No comments: