Bash
sudo:無法執行 ./script.sh:沒有這樣的文件或目錄
我難住了。我的
/home
目錄中有一個可執行的腳本:[user@server ~]$ ll total 4 -rwx------ 1 user user 2608 Jul 15 18:23 qa.sh
但是,當我嘗試使用它執行它時
sudo
說它找不到它:[user@server ~]$ sudo ./qa.sh [sudo] password for user: sudo: unable to execute ./qa.sh: No such file or directory
這是一個全新的版本。沒有進行任何會導致問題的更改。事實上,腳本的重點是確保它實際上是根據我們的策略建構的。也許它不是並且
sudo
實際上在建構過程中被破壞了?我還應該注意,我可以
sudo
在其他目錄中使用其他命令執行。編輯:腳本(我沒有寫,所以請不要
/bin/bash
讓我超過它;))#! /bin/bash . /root/.bash_profile customer=$1 if [ -z "$customer" ]; then echo "Customer not provided. Exiting..." exit 1 fi space () { echo echo '###########################################################################' echo '###########################################################################' echo '###########################################################################' echo } g=/bin/egrep $g ^Listen /etc/ssh/sshd_config $g ^PermitR /etc/ssh/sshd_config $g ^LogL /etc/ssh/sshd_config $g ^PubkeyA /etc/ssh/sshd_config $g ^HostbasedA /etc/ssh/sshd_config $g ^IgnoreR /etc/ssh/sshd_config $g ^PermitE /etc/ssh/sshd_config $g ^ClientA /etc/ssh/sshd_config space $g 'snyder|rsch|bream|shud|mweb|dam|kng|cdu|dpr|aro|pvya' /etc/passwd ; echo ; echo ; $g 'snyder|rsch|bream|shud|mweb|dam|kng|cdu|dpr|aro|pvya' /etc/shadow space $g 'dsu|scan' /etc/passwd ; echo ; echo ; $g 'dsu|scan' /etc/shadow space $g ${customer}admin /etc/passwd space chage -l ${customer}admin space $g 'urs|cust|dsu' /etc/sudoers space $g dsu /etc/security/access.conf space $g account /etc/pam.d/login space /sbin/ifconfig -a | $g addr | $g -v inet6 space echo "10.153.156.0|10.153.174.160|10.120.80.0|10.152.80.0|10.153.193.0|172.18.1.0|10.153.173.0" echo $g '10.153.156.0|10.153.174.160|10.120.80.0|10.152.80.0|10.153.193.0|172.18.1.0|10.153.173.0' /etc/sysconfig/network-scripts/route-eth1 space cat /etc/sysconfig/network-scripts/route-eth2 space netstat -rn | tail -1 space cat /etc/sysconfig/iptables space cat /etc/hosts space ##file /usr/local/groundwork ; echo ; echo ; /sbin/service gdma status ##space cat /etc/resolv.conf space HOSTNAME=`echo $HOSTNAME | awk -F. '{ print $1 }'` nslookup ${HOSTNAME} echo echo nslookup ${HOSTNAME}-mgt echo echo nslookup ${HOSTNAME}-bkp space /sbin/service rhnsd status ; echo ; echo ; /sbin/chkconfig --list rhnsd ; echo ; echo ; yum update --security space /sbin/service osad status ; echo ; echo ; /sbin/chkconfig --list osad space /sbin/service sshd status ; echo ; echo ; /sbin/chkconfig --list sshd space /sbin/service snmpd status ; echo ; echo ; /sbin/chkconfig --list snmpd ; echo ; echo ; echo ; cat /etc/snmp/snmpd.conf space df -h space cat /proc/cpuinfo | $g ^processor space free -g space if [ -f /etc/rsyslog.conf ]; then tail -3 /etc/rsyslog.conf else echo "This system is not running rsyslog." fi rm -f $0
這通常發生在
#!
腳本中的 shebang ( ) 行損壞時。shebang 告訴核心文件需要使用解釋器執行。不帶 執行時
sudo
,消息更有意義。但隨著sudo
你得到你得到的資訊。例如:
$ cat test.sh #!/bin/foo echo bar $ ./test.sh bash: ./test.sh: /bin/foo: bad interpreter: No such file or directory $ bash test.sh bar $ sudo ./test.sh sudo: unable to execute ./test.sh: No such file or directory $ sudo bash ./test.sh bar
該
bad interpreter
消息清楚地表明這是有問題的shebang。