Bash 스크립트에서 Apt-get이 실패합니까?

Bash 스크립트에서 Apt-get이 실패합니까?

동일한 방식으로 구성해야 하는 여러 시스템(Ubuntu LTS 12.4 64비트 실행)이 있으므로 시스템이 처음 부팅될 때 자동으로 실행되는 셸 스크립트를 만들었습니다. 대부분의 경우 작동하지만 apt-get에 대한 호출은 실패합니다. 예를 들어, 실행하려는 두 가지 명령이 있습니다.

debconf-set-selections ./files/ldap.preseed
apt-get -y install ldap-auth-client

해당 줄을 직접 입력하면 결과는 다음과 같습니다.

root@spare:/tmp/scripts# debconf-set-selections ./files/ldap.preseed
root@spare:/tmp/scripts# apt-get -y install ldap-auth-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be installed:
  ldap-auth-config libnss-ldap libpam-ldap
The following NEW packages will be installed:
  ldap-auth-client ldap-auth-config libnss-ldap libpam-ldap
0 upgraded, 4 newly installed, 0 to remove and 67 not upgraded.
Need to get 0 B/200 kB of archives.
After this operation, 877 kB of additional disk space will be used.
Preconfiguring packages...
[and so on...]

그러나 해당 줄만 포함하는 쉘 스크립트를 실행하면 다음과 같은 일이 발생합니다.

root@spare:/tmp/scripts# ./ldap.cr
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package ldap-auth-client

sudo를 사용하여 스크립트를 실행하거나 먼저 루트로 chown할 때도 동일한 문제가 발생합니다. 프로그램이 직접 호출되거나 쉘 스크립트를 통해 호출되는 경우 프로그램의 차이점은 무엇입니까? 그리고 다르게 설득하는 것이 가능합니까?

편집: 추가 정보:

root@spare:/tmp/scripts# apt-cache policy ldap-auth-client
ldap-auth-client:
  Installed: (none)
  Candidate: 0.5.3
  Version table:
    0.5.3.0
       500 http://us.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages

답변1

실행하기 전에 dos2unix를 통해 스크립트를 실행하면 제대로 작동했습니다. 나는 apt-get이 패키지 이름의 일부로 줄 끝의 추가 \r을 읽고 따라서 ldap-auth 대신 ldap-auth-client\r(존재하지 않음)을 찾고 있다고 추측합니다. -클라이언트(그렇습니다).

답변2

다음 명령을 실행해보십시오

apt-get update         

실행하기 전에적절한 설치명령

또한 URL이/etc/apt/sources.list사용할 수 있습니다.

관련 정보