Windows Task with Bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Windows Task with Bash script
# 1  
Old 08-07-2015
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 :
Code:
ERROR 2 (HY000) at line 2: File '.\xxx.csv' not found (Errcode: 2)

Code Line :
Code:
load data local infile './xxx.csv' REPLACE into table datebase.table

Thenks for any help
# 2  
Old 08-07-2015
Are trying to run the script with task scheduler or are you using task scheduler to call cygwin to run the script?
# 3  
Old 08-07-2015
I'm make task in Task Scheduled with parametres :
Code:
c:\cygwin\bin\bash.exe -l -c "/full/path/to/command/plus-command >> /full/path/to/a/logfile 2>&1"

# 4  
Old 08-07-2015
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:

Code:
#! /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
# 5  
Old 08-10-2015
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.
# 6  
Old 08-10-2015
Quote:
Originally Posted by karp
I'm understend fStart Directory. It can be usefull. Why do you use fOutput ?
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".

Quote:
Originally Posted by karp
If I use full directory string "/cygdrive/d/.../.../tmp.csv", it doesn't work.
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
# 7  
Old 08-11-2015
Quote:
Originally Posted by bakunin
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?
n
Error :
Code:
ERROR 2 (HY000) at line 1: File '\cygdrive\d\Load\tmp_d_.csv' not found (Errcode: 2)

Code in script :
Code:
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 ;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for database task.

Hi, I need help in creating script for "User password reset in database" by logging into database from linux server and resetting the user password. Could you please provide the script for this task? Steps are given below. 1. Login into database from server sqlplus... (5 Replies)
Discussion started by: Maddy123
5 Replies

2. Shell Programming and Scripting

Run a task in a script at a particular time

I have an ETL process that triggers a shell script. This script picks the files created by the ETL process and does an SFTP. These are huge files. Due to infrastructure limitations, we need to trigger the actual SFTP part only during the 2nd, 16th, 31st and 46th minute of an hour. Please let me... (2 Replies)
Discussion started by: vskr72
2 Replies

3. Shell Programming and Scripting

How to do one line bash schedule task?

This seems to work: https://www.unix.com/shell-programming-scripting/179705-how-run-cygwin-bash-windows-scheduled-task.html However, I was hoping to avoid writing a 2 line bat files to invoke my cygwin scripts as a scheduled task (since I'm making lots scheduled tasks). I was hoping this would... (1 Reply)
Discussion started by: siegfried
1 Replies

4. Shell Programming and Scripting

Whether Shell script can do this task ???

In following attached 748phy.xls file, fifth column is ST_Date, which contains time and dates in this format 22-11-2012 7:54:54 PM in single column I want it to split in this format either 1st column 22/11/2012 and in second column 7:54:54 PM Or like this in separate... (13 Replies)
Discussion started by: Akshay Hegde
13 Replies

5. Shell Programming and Scripting

Can any programmer do this task in shell script...

input file's one set header is this, ----------------------------------------------------- OUTPUT FROM ASCII FILE: CAST #1 ----------------------------------------------------- CC Cruise Latitude Longitude YYYY MM DD Time Cast #Levels CA 8504 50.083 -144.883 1970 1 2... (6 Replies)
Discussion started by: Akshay Hegde
6 Replies

6. Shell Programming and Scripting

How to run Cygwin bash from windows scheduled task?

Hmmm.... I love these forums because I always get great prompt responses and I want to ask a question about running bash on windows. Is that allowed? Now I know I can install cygwin cron and run bash that way. Can I run bash from windows schedule task? How? thanks siegfried (1 Reply)
Discussion started by: siegfried
1 Replies

7. Shell Programming and Scripting

command task script

ksh $CODE/dis/scripts/IS_BTEQ_LZ_TABLE_AUDIT.sh DIS_BTEQ LZ_DIS_LOAD_LOG_KEY > $CODE/dis/logs/lz_table_audit_`date '+%Y%m%d_%H%M%S'`.log 2>&1 Can some one tell me what the above script is doing? As per my understanding we are executing the script and sending the output to a log file. The... (4 Replies)
Discussion started by: karthikkasarla
4 Replies

8. Shell Programming and Scripting

last task for my script

hi, infile- create table salary ( occupation_code char(40), earnings decimal(10,2), occ_yearend integer ); outfile- salary:create table salary salary:( occupation_code char(40), salary: earnings decimal(10,2), salary: occ_yearend integer salary:); Thanks. (4 Replies)
Discussion started by: dvah
4 Replies

9. UNIX for Dummies Questions & Answers

BASH: Change alias to script to add a task

Hi. I use an alias, "homeperm" as shorthand for curl -o. Since most of what I download via cUrl is graphic image files -- jpeg files -- I'd like to be able to change this alias to a script, or use it to invoke a function, which will not only download the file but date-stamp it using Exiv2 in... (4 Replies)
Discussion started by: SilversleevesX
4 Replies

10. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies
Login or Register to Ask a Question