Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i need to run dos2unix on a file to fix some line endings
from a wxp text file. i'm trying to do this from a script.
what's the syntx to do this? i have this:
What error is it producing? Have you looked at the man page? You need to specify an output file. The following is from http://linux.die.net/man/1/dos2unix:
actually, i just cd'ed to the file's directory and did a test by typing:
Code:
dos2unix filename_to_process.txt
into a terminal and the resultant file became usable so that was as far
as i ever took it. i'm just trying to replicate that from a script now.
the file is a txt file which i'm parsing. it carries a lot variable
values for another app. once i've moved it into my mandriva box i just
need to get rid of the extra windows characters at the line ends for
my app to be able to run. my first test worked fine with no extra
parameters or anything, just the line above.
Is the dos2unix binary in the current working directory? Because that's where bash is looking for it.
If he's having such a problem with such a simple thing, I'd try to be more explicit when answering.
babag, you need to remove the ./ on the script, in other words, the contents of the script should be this:
Code:
#!/bin/bash
dos2unix /path/to/filename.txt
I added the shabang of the first line for the sake of correctness. Still, I can't understand the purpose of this script, unless it's just for educational purposes.
Feel free to ask anything else if this is not the info you needed.
/home/processing-01/Documents/Scripts/d2u_and_nconvert.sh: line 5 ./usr/bin/dos2unix: No such file or directory.
i'm starting to think that this is a more complex issue having to do with ssh.
it's true that on my local box /usr/bin/dos2unix does not exist.
script 1 on my local box calls dos2unix_and_nconvert.sh on a remote box,
though. that's when i get the error. i'm wondering if things are confused
between the two boxes and the error is referring to the local box?
will post an ssh question on the networking forum.
/home/processing-01/Documents/Scripts/d2u_and_nconvert.sh: line 5 ./usr/bin/dos2unix: No such file or directory.
i'm starting to think that this is a more complex issue having to do with ssh.
it's true that on my local box /usr/bin/dos2unix does not exist.
script 1 on my local box calls dos2unix_and_nconvert.sh on a remote box.
that's when i get the error. i'm wondering if things are confused between
the two boxes and the error is referring to the local box?
thanks,
BabaG
Try what I posted above, you are unnecessarily adding complexity. dos2unix is a standard tool which is in the system path 100% of the times (unless it's not installed).
"./usr/bin/dos2unix" means "go to usr/bin starting from the current dir, and look for an executable file called dos2unix"
In other words, if you log in with the user name "i92", your path is translated as "/home/i92/usr/bin/dos2unix". So, again, remove the path, leave just "dos2unix".
I am assuming that the machine you are login to has this tool installed, if not, you will need to either add it to some dir on your home dir which is in your $PATH, ask your admin to install it for you globally or implement this in any other way (there are more ways).
As mentioned above, dos2unix is normally in the list of dirs in your PATH shell variable.
./blah/blah
'./' means start in the current dir (ie where your shell is pointing when you run the cmd), so in
./usr/bin/dos2unix
its saying; starting in the current dir (.), look for a subdir called usr, look in there for a subdir bin and look in there for a prog dos2unix.
if you had
/usr/bin/dos2unix
that means start at the root dir (/), ie root of the filesystem and work down as described above.
Note that the root dir has nothing to do with the root user.
FYI, '.' means current dir, '..' means parent dir (ie 1 above the current dir).
removing the '.' at the start seems to have done it.
have another issue as i'm unsure dos2unix actually ran,
but i'm at least past that error.
{edit}
it appears that dos2unix did not run. i had a copy of
the text file sitting around that i had previously run
dos2unix on. first i tried to manually run my processing
app on the remote and it produced a segmentation error.
then i switched the textfile for the one i knew dos2unix
had been run on. ran the processing app again. no error.
looks like, while i've managed to remove the error when i
try to run dos2unix from my script, dos2unix does not
actually run.
thanks, i92guboj. let me see if i have this right.
i know that dos2unix is installed on the remote boxes that
are being called. the textfile that needs to be changed by
dos2unix is also on the remote boxes. since i know they are
both there, and i know it's not working, are you saying that
i need for dos2unix to be installed on the local box? that's
where the call is being made from. are you saying that the
local installation of dos2unix would be doing the processing
of the remote text file? that's all i can figure since i
know both dos2unix and the textfile are on the remote box.
sorry for being so obtuse, but this ssh stuff is a kind of a
mindbender for this n00b, especially with scripts calling other
scripts and the like.
thanks for your patience. i'm rereading your posts.
BabaG
thanks, i92guboj. let me see if i have this right.
i know that dos2unix is installed on the remote boxes that
are being called. the textfile that needs to be changed by
dos2unix is also on the remote boxes. since i know they are
both there, and i know it's not working, are you saying that
i need for dos2unix to be installed on the local box?
No, as long as you are logged via ssh onto a remote box, then all the tools you invoke will run on that box. You don't need anything in local.
Anyway, to try to debug the issue, can you try manually loging in via ssh and then running dos2unix manually there? That could help us to understand what the problem is, if any.
Don't hesitate to ask as many times as you need. As long as you put some effort on your side I don't have a problem on giving some minutes of mine either.
thanks so much for your time i92guboj. i'm actually not
at the site now and have pretty much exhausted what i can
do without being at the boxes. will try as you suggest
tomorrow when i get in. wil try running dos2unix locally
as well as via a manual ssh login. won't be for 14 or 15
hours, though.
which seemed to sort of run it but not correctly. the output to screen that the script
should have made was basically there but things were a bit off and the processing of files
never happened. filenames were wrong and such. that's why they never got processed. the
names were output to screen as if they were processing but were missing characters like
'-'. that meant i could see the script was trying to run but had incorrect filename info so
they never got processed.
i then manually navigated to the folder containing the script:
Code:
cd /home/user_acct/Documents/Scripts
and, from there, ran the script:
Code:
./d2u_and_nconvert.sh
this actually worked. the filenames displayed correctly on the screen ands the processing
did occur.
so, i guess my question would be how to interpret this into my script:
connection was made manually via ssh using the same ssh command as earlier indicated.
script directory was manually navigated to.
script was manually run from within its directory.
apologies. been trying to edit my last post to swap the
first two examples of things i tried because i, obviously,
inverted them. the ./ was the first thing and th / was
the second. whenever i try to edit them, though, my
connection times out. sorry. something odd is going on
with my dsl line in this studio.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.