Link to home
Start Free TrialLog in
Avatar of aideb
aideb

asked on

Run DOS2UNIX and then execute the command

Hi,

I have a command line that I need to reorganise

wget -O - http://kalideploy.azurewebsites.net/test.sh | dos2unix | sudo bash -x

I'm using the Linux custom script deployment and it will fetch the file for me - so I don't need wget

The script needs converted using the dos2unix before execution

I've tried a variety of different command lines but cannot work out where its going wrong

Can anyone help?
Avatar of Frank McCourry
Frank McCourry
Flag of United States of America image

Your example looks like you are piping one command to the other, which is fine, but the dos2unix portion of the command is missing parameters.  Here is the manual:  http://waterlan.home.xs4all.nl/dos2unix/dos2unix.htm
Can you try:

echo $(wget -O - http://kalideploy.azurewebsites.net/test.sh)  | dos2unix | sudo bash -x

What is the output of the wget command?
Avatar of aideb
aideb

ASKER

@Frank

What parameter do you think is missing?

For clarity, the command above runs when executed normally

When running via Azure, I would usually run

sh script.sh

however I need to run it through the dos2unix converter
Avatar of aideb

ASKER

@Gerwin

Sorry, that just hangs

oot@KaliB005:/home/labuser# echo $(wget -O - http://kalideploy.azurewebsites.net/test.sh)  | dos2unix | sudo bash -x
--2017-01-16 13:29:51--  http://kalideploy.azurewebsites.net/test.sh
Resolving kalideploy.azurewebsites.net (kalideploy.azurewebsites.net)... sudo: unable to resolve host KaliB005
13.95.238.192
Connecting to kalideploy.azurewebsites.net (kalideploy.azurewebsites.net)|13.95.238.192|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2511 (2.5K) [application/x-sh]
Saving to: ‘STDOUT’

-                                 100%[=============================================================>]   2.45K  --.-KB/s    in 0s      

2017-01-16 13:29:54 (544 MB/s) - written to stdout [2511/2511]
SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aideb

ASKER

@omarfarid

I get the following error

No such file or directory
what is the output of

wget -O - http://kalideploy.azurewebsites.net/test.sh | dos2unix
Avatar of aideb

ASKER

@omarfarid

It outputs the contents of the script

Thanks
if the script is multiple lines then you may need to store in file then execute that file. It may also be that the script has folders of files names that it can't find
>> I would usually run sh script.sh <<

I understand that there is a script "script.sh" in DOS format which you want to run, converting it to Unix format "on the fly", leaving the original "script.sh" as is. If I'm right, try:

dos2unix < script.sh | sh

The above will not work if the script itself needs to read from stdin or if the script expects command line arguments!
What is your goal with that test script you are downloading?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aideb

ASKER

The issue is that I need an easy way in which to edit the script - and I'm editing on a Windows based PC. Each time I save the file on Windows, I need to run it through Dos2Unix else it fails

Perhaps I'm going to have to do all the edits on the remote Linux box and then upload from there...

Does anyone have a better solution?
Avatar of aideb

ASKER

I'm trying to build multiple VM's using the Linux custom script extension on Azure


https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-extensions-customscript
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aideb

ASKER

I really wanted to be able to continue to use the web based App Service editor on Azure to edit - hence the use of Dos2Unix
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is http is the only way to access the file and download the script file? If you have ftp access then using ftp you can download file as text which will convert the control M
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aideb

ASKER

Hi woolmilkporc

Yes, I tried your suggestion - Thanks
It works fine from a terminal session but not from the Azure template
Avatar of aideb

ASKER

Thanks everyone for all your input.

I've revised my approach as suggested and I'm now editing the file on Windows using Notepad++ preserving the file encoding thus avoiding having to fix it when it arrives on the Linux machine. Its not quite how I wanted to do it, however it is working!

Thanks