Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have several machines (running Ubuntu LTS 12.4 64-bit) which need to be configured in the same way, so I created a shell script which will run automatically the first time the machine boots. It works for the most part, but any call to apt-get fails. As an example, here are two commands I want to execute.

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

Here is the result if I type those lines directly:

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...]

But if I execute a shell script containing only those lines, this happens:

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

The same thing occurs when I run the script using sudo, or chown it to root first. What is the difference, to the program, if it is being called directly or through a shell script? And is it possible to convince it otherwise?

EDIT: More information:

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
share|improve this question
    
Show the contents of the script, otherwise we may not know. –  Braiam Oct 16 '14 at 15:01
    
It's the two commands given at the top: debconf-set-selections followed by apt-get. –  Draconis Oct 16 '14 at 15:05
    
Are you sure that's the only content of the script? cat ldap.cr? And are both on the same system? apt-cache policy ldap-auth-client –  Braiam Oct 16 '14 at 15:06
    
There was an echo at the beginning and an echo at the end, but I commented them out. –  Draconis Oct 16 '14 at 15:10

2 Answers 2

Running the script through dos2unix before executing it caused it to work properly. I'm guessing that apt-get was reading the extra \r at the end of the line as part of the package name, and thus looking for ldap-auth-client\r (which doesn't exist) instead of ldap-auth-client (which does).

share|improve this answer

Try to run the following command

apt-get update         

before executing apt-get install command

Also make sure that urls in /etc/apt/sources.list are available.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.