Windows Task with Bash script

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

Thenks for any help

Are trying to run the script with task scheduler or are you using task scheduler to call cygwin to run the script?

I'm make task in Task Scheduled with parametres :

c:\cygwin\bin\bash.exe -l -c "/full/path/to/command/plus-command >> /full/path/to/a/logfile 2>&1"

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"

I hope this helps.

bakunin

I'm understend fStart Directory. It can be usefull. Why do you use fOutput ?

If I use full directory string "/cygdrive/d/.../.../tmp.csv", it doesn't work.

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.

I hope this helps.

bakunin

Error :

ERROR 2 (HY000) at line 1: File '\cygdrive\d\Load\tmp_d_.csv' not found (Errcode: 2)

Code in script :

mysql -e "load data local infile '/cygdrive/d/Load/tmp_d_.csv' REPLACE into table datebase.table
  COLUMNS TERMINATED BY '|'
  LINES TERMINATED BY '\n'
  (D_N, @D_Date, D_Pages,D_ID)
  set
  D_Date = str_to_date(@D_Date, ' %a %b %d %H:%i:%s %Y')
    " -u admin -pPassword ;

Are you sure \cygdrive\d\Load\tmp_d_.csv really exists? Doesn't windows convention need a drive letter to indicate a full path?

\cygdrive\d\Load\tmp_d_.csv

It's a correct linux directory.

D:\Load

It's give me the same error.

I was rather thinking of sth. like C:\cygdrive\d\Load\tmp_d_.csv And certainly \cygdrive\d\Load\tmp_d_.csv is not a correct linux directory.

I tried it.
Error

ERROR 2 (HY000) at line 1: File 'C:\cygdrive\d\CasusLoad\tmp_d_.csv' not found (Errcode: 2)

Linux directories are separated by / not \ as in Windows.

So maybe its:

/cygdrive/d/CasusLoad/tmp_d_.csv

hth

EDIT:
Figured, according to output of last post of previous page, it seems that the path passed - somewhere - gets transformed

Just in case it is not clear.

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.

1 Like
./tmp_d_.csv

Work well in cygwin
Give Error in Window Task

ERROR 2 (HY000) at line 2: File '.\xxx.csv' not found (Errcode: 2)

Windows change

/

to

\

in Error
2.

/cygdrive/d/Load/tmp_d_.csv

Doesn't work in cygwin.
Doesn't work in Windows Task
Error :

ERROR 2 (HY000) at line 1: File '\cygdrive\d\Load\tmp_d_.csv' not found(Errcode: 2)
D:\CasusLoad\tmp_d_.csv

Doesn't work in cygwin.
Doesn't work in Windows Task

What is the absolute path of the file in windows?

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.

I hope this helps.

bakunin

ERROR 2 (HY000) at line 1: File '\cygdrive\d\Load\.tmp_d_.csv' not found (Errcode: 2)

---------- Post updated at 05:00 AM ---------- Previous update was at 03:30 AM ----------

Problem gone.
I was thinking the

cd

don't work in bash.
It's working in cygwin and windows task.