Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Need a bit help. I just wrote my first script to change the network configuration. the code is

echo "changing IP to"
echo "changing Mask to"
echo "changing Gateway to"

sed -i 's/.*IPADDR.*$/IPADDR=' /etc/ifcfg-eth0.txt
# ne need to change mask sed -i 's/.*IPADDR.*$/IPADDR=' /etc/ifcfg-eth0
sed -i 's/.*GATEWAY.*$/GATEWAY=' /etc/ifcfg-eth0.txt

I copied the icfg-eth0 file to the etc folder for testing purpose. When I run the script I get the error

:No such file or diretorytxt
:No such file or diretorytxt

But when I just use the commands on the prompt the command works and changes what I want it to change.

Any idea why its not working when running as a script?

AsteriskNOWv3(CentOS 6.2)

share|improve this question
Is that an exact copy/paste of your script? The second sed is on a commented-out line, and the middle file doesn't have the .txt extension and doesn't include MASK or 255...? – beroe Sep 1 '13 at 6:58

The most likely reason is you have edited your script on Windows and its lines are terminated with CR-LF instead of the expected single LF.

Use the dos2unix command to fix it.

dos2unix script

Alternatively, you can simply run

tr -d `\r` < script > script.fixed
share|improve this answer

Looks to me like you have added ".txt" to the files you are writing - this would seem wrong, as the bit after the "." is deemed to be a VLAN, and .txt is, of-course not a valid VLAN.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .