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)

  • 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
  • Also, how are you running your script? – niglesias Mar 15 '19 at 18:56

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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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