Hello
I have a problem with use bash script in windows task.
If I use script by cygwin it's working well.
If I use it by Windows task I'm get error
Error :
ERROR 2 (HY000) at line 2: File '.\xxx.csv' not found (Errcode: 2)
Code Line :
load data local infile './xxx.csv' REPLACE into table datebase.table
I am not an expert on Windows, so take my suggestion cum grano salis as the problem might be everything else and then some.
Still, i think you should definitely, absolutely AVOID RELATIVE PATHES in any script you write: command ./file as a scripts line will work as long as you call the script from the directory the file is in, because ./file means the file named "file" in the current directory.
But what you want (and which might be the reason why this fails) is that some abosulte path because the calling process (your task scheduler or whatever the thing Windows has instead of cron ) has perhaps another current directory than your terminal session.
I usually manage these absolute pathes by defining starting directories and work from there, like this:
#! /bin/sh
fStart="/some/place/to/start"
fOutput="/another/directory"
# here is a sample command:
cp "$fStart"/myfile "$fOutput"/otherfile
# or like this:
fSource="${fStart}/myfile"
fTarget="${fOutput}/otherfile"
cp "$fSource" "$fTarget"
For the same reason why i use "fStart": using a variable (instead of a fixed string) i define it once and if i ever have to use another directory i have to change the string only in one place in the script.
The "f" in front of variable names is a reminder for me that the variable contains a path name (the "f" is for "file"). This way i can better keep track of my variables in use, a method called "Hungarian Notation".
Basic debugging 101: What have you done using full directory strings? How has it "not worked"? Were there any diagnostic messages? Error codes? Complaints from the neighbors? Anything?
I don't know if "/cygdrive/d/.../.../tmp.csv" was just a deliberate abbreviation (in this case better use /cygdrive/d/[...]/tmp.csv ) or if you entered the path literally like that. If the latter: this is not a legal path name.
That does exist only when working from within cygwin.
\cygdrive\d\CasusLoad\tmp_d_.csv
Does not exist in Windows nor when running cygwin
/cygdrive/d/CasusLoad/tmp_d_.csv
Is the equivalent to D:\CasusLoad\tmp_d_.csv if you want to locate it using Windows Explorer.
You can know how it will be mapped when running cygwin by issuing the mount command.
Since we cannot see what is going on on your system, you will have to interpret what we tell you: if it doesn't work as given literally you will have to try to understand the meaning and try to variate it accordingly.
Having said this:
OK. This means take the file tmp_d_.csv in the current directory, so: which is this current directory? Issue the command pwd (which will tell you exactly that) and save its output.
For the rest of this let us assume the output is "/some/where" (no - it is not, actually, but you will have to substitute the real value for this yourself).
Now replace /.tmp_d_.csv (relative path) by /some/where/.tmp_d_.csv (absolute path) and run again. Do so analogously for all the other pathes and path names you use.
If you still have troubles:
post the output of the mount command. It will tell you which (parts of the) Windows file systems are accessible via which UNIX pathes and vice versa.