ssh 远程调用解决环境变量方法

         远程调用ssh命令时候,有可能会遇到系统无法加载而导致脚本执行不了,而本地执行时,却正常,这时候会让很多人郁闷,这是为什么呢,原来ssh登录时候,non-interactive + non-login: 不读取任何文件.so ,为什么执行不了吧。

         就此原因,有两种办法:

         一是在shell 里加上  export BASH_ENV=/etc/profile,如果还不行,第一行改#!/usr/bin/env bash再执行

       二是#!/bin/bash --login,如此一来,bash便会强制为login shell,所以/etc/profile也会被加载。

       source XXX.sh

   

参考:http://www.kuqin.com/shuoit/20141113/343188.html

   

猜你喜欢

转载自hugoren.iteye.com/blog/2240398