首页 > 运行通过ssh连接的远程计算机上的sh文件和运行本地的一样么?

运行通过ssh连接的远程计算机上的sh文件和运行本地的一样么?

通过scp 将本地的sh文件上传到了 远程计算机
通过vim查看文件内容也没错 在本地运行也没错
但是在ssh连接远程计算机后,运行a.sh
提示command not found。。。。
[coffee@localhost stress]$ ls
stress-test-0.0.1-SNAPSHOT.jar stress-test-thread.sh
stress-test-2015-05-13.log stress-test-time.sh
[coffee@localhost stress]$ stress-test-thread.sh 100 check
-bash: stress-test-thread.sh: command not found
怎么回事啊?
谢谢


你需要将stress-test-thread.shmode改为可执行的.

$ chmod +x stress-test-thread.sh

  1. 脚本直接执行需要有可执行权限:
    使用ls -lrt看看,是否有可执行权限,没有的话加上:chmod +x stress-test-thread.sh

  2. 你使用a.sh执行的方式是会到全局path中搜索a.sh这个可执行文件,你的当前path不再全局path的环境变量中是找不到的,就会报command not found;
    几种解决方法:
    1)使用./a.sh的方式执行本目录下的可执行文件;
    2)将当前目录添加到全局path环境变量中,或者将a.sh添加到/bin/这样的全局path中(or加在这类path加一个符号链接)

  3. 脚本没有可执行权限的情况可以使用以下方式执行:
    source a.sh
    . a.sh

【热门文章】
【热门文章】