I realize this might be hard to answer without you knowing how my cluster is setup, but I' am trying to submit jobs (via SGE) to a cluster, but the environment is not setup correctly and the jobs fails. Moreover, there are two different master nodes I can login into to submit jobs to the same cluster, and my scripts work on one while not on the other.The is the machine info for the master node that my script does work on:cat /proc/version Linux version 2.6.32-279.el6.x86_64 (mockbuild@x86-008.build.bos.redhat.com) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) ) #1 SMP Wed Jun 13 18:24:36 EDT 2012The machine it does not work on:cat /proc/versionLinux version 3.10.0-514.6.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Thu Feb 23 03:04:39 UTC 2017Here is a test script I' am using:#!/bin/bash -I#$ -wd ~#$ -N test#$ -o ~/test.log#$ -j y#$ -terse#$ -V#$ -notify#$ -l h_vmem=2G -pe smp 1 -l athena=truelshostnamenprocHere is the output after running qsub test.sh:/bin/bash: module: line 1: syntax error: unexpected end of file/bin/bash: error importing function definition for `BASH_FUNC_module'/opt/sge/default/spool/execd/node156/job_scripts/1063646: line 11: ls: command not found/opt/sge/default/spool/execd/node156/job_scripts/1063646: line 12: hostname: command not foundTo add to the confusion, when I ssh directly into those job nodes (node156 in the above example) I can run the ls and hostname commands just fine!I've been in contact with the cluster admins, and they are unable to replicate my issue (even if they login as me). We first tested that if setting ~/.bashrc and ~/.bash_profile to default settings would fix it, but it did not. Here are those files:cat ~/.bashrc # .bashrc# Source global definitionsif [ -f /etc/bashrc ]; then    . /etc/bashrcfi.bash_profile:cat ~/.bash_profile # .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then    . ~/.bashrcfi# User specific environment and startup programsAny suggestions?
Job environment not being setup correctly on SGE
bash;cluster
I don't have a full solution, because I don't know anything about SGE. But I can explain part of the problem.The machine where your script works is running an old version of the operating system. This is evident not only by the kernel version number, but also by the fact that it hasn't received security updates in a while. Specifically, I think it's running a version of bash that's vulnerable to the Shellshock bug.Bash (ab)uses the environment to pass functions. Normally the environment is only used to pass data, in the form of a series of items of the form NAME=VALUE. Older versions of bash add items of the form NAME=() {CODE}, which in some circumstances allowed injecting code by defining a variable that a script would never use the shellshock bug. The fix for the bug changed the way functions are encoded to BASH_FUNC_NAME%%=() {CODE}.Evidently some part of your setup dumps out the environment and parses it. This may either be a part of SGE or something specific to your setup. A plausible reason to do this is to save the environment in which a job was submitted, to execute the job in the same environment.Something somewhere is defining a function called module in bash, and exporting it. The code would look something likemodule () {  }export -f moduleThe fix is either to upgrade the environment parser to something that can cope with the new bash encoding, or to stop exporting functions.