Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

echo "changing IP to 172.17.51.71"
echo "changing Mask to 255.255.255.0"
echo "changing Gateway to 172.17.51.254"

sed -i 's/.*IPADDR.*$/IPADDR=172.17.51.71/g' /etc/ifcfg-eth0.txt
# ne need to change mask sed -i 's/.*IPADDR.*$/IPADDR=172.17.51.71/g' /etc/ifcfg-eth0
sed -i 's/.*GATEWAY.*$/GATEWAY=172.17.51.254/g' /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

2 Answers 2

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

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.