Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I create a small script that installs a set of linux paquets .

Strangely apt-get install always fails and tells me that the package have not been found. Here is my script:

#! /bin/bash
sudo apt-get install python-software-properties
sudo apt-get update
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get install xfce4 postgresql-9.0 pgadmin3 chromium-browser wine iftop

What can i do to fix this ?

Thanks .

share|improve this question
    
Can you post the results of sudo apt-get install --simulate xfce4 postgresql-9.0 pgadmin3 chromium-browser wine iftop ? –  jdw Sep 28 '11 at 17:41
    
in fact it fail at the first line : –  isoman Sep 28 '11 at 17:49
1  
How does it fail? I've tried apt-get --simulate install <the rest> and apt-get install --simulate <the rest> and both succeed on my machine. Can you post more info on how it is failing? Although, I have to say that both George and Shane have good points. You should try those first. –  jdw Sep 28 '11 at 17:56

5 Answers 5

up vote 2 down vote accepted

First line of your script. Remove the space.

#!/bin/bash

Also what @Shane said: on a script you may want to use -y to automate the process.

Update
Have you run chmod +x scriptname before trying to run it? Can you please post the exact error you're getting?

share|improve this answer
2  
This is only a convention, not mandatory. Quoting Dennis Ritchie, en.wikipedia.org/wiki/Sha-bang#History "To take advantage of this wonderful opportunity, put #! /bin/sh at the left margin of the first line of your shell scripts. Blanks after ! are OK." –  Andrew Sep 29 '11 at 1:59
    
You're right, I double checked a simple bash script and it works both with a space between #! and /bin/sh as well without one. But @isoman mentioned that his script is failing in the first line so I thought he give it a try. We'll have to wait for his feedback. –  George Tasioulis Sep 29 '11 at 9:33

If you're trying to install something from that PPA repository, your apt-get update should happen after you add the repo, not before.

You'll want a -y on the potentially interactive steps, too.

share|improve this answer

also you should first update apt-get and then install so the script should look like

#! /bin/bash
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install python-software-properties
sudo apt-get install xfce4 postgresql-9.0 pgadmin3 chromium-browser wine iftop

next make the file executable

chmod 755 script
share|improve this answer
    
well i tried with this tiny script to isolate the problem: #!bin/bash apt-get install -y iftop . i get an error telling that it can't find the package . When i run this commmand manually it work fine . –  isoman Sep 30 '11 at 11:35

Start using version control for system admin scripts. This will help highlight issues as raised by @volker238.

Especially distributed systems like Mercurial or Git will help getting the code across correctly. Both will properly convert line endings cross-platform.

Several times, when I received Copy/Paste contributions from others, the hg log told me exactly what had changed when the shell complained about syntax errors, and nothing obvious could be seen.

And if you want to scale up further, combine this with chef or puppet, to create repeatable deployment plans for your systems.

share|improve this answer

I was having the exact same issues. The real key to solving this was the error on the first line #!/bin/sh. I was writing my script on a Windows machine and the Ubuntu box was a VM. Some Windows line endings were messing me up. I fixed it with dos2unix as referenced here.

share|improve this answer
    
/bin/sh in Ubuntu is not necessarily Bash. Check your install's symlinks. Good odds you'll find it's set to Dash instead. –  Magellan Sep 30 '12 at 21:32

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.