I am using Execute process task in SSIS to execute below command line arguments to download the files to some local drive.
/log=G:\USER_DATA\IRM\IRM_SFTP_Logs\IRM_SFTP_Log_Details.txt /command "open sftp://bisftp:*UFVy2u6jnJ]#hU0Zer5AjvDU4#stransfer.xxx.com/ -hostkey=""ssh-rsa 2048 xxxxxxxxxxxxx""" "cd /DATA" "get GNRC_IRM_XXXX_EXTRACT*.zip GNRC_IRM_XXXX*.zip G:\USER_DATA\IRM\IRM_Download\" "exit"
This is running perfect and every time it appends logs to the existing file.
G:\USER_DATA\IRM\IRM_SFTP_Logs\IRM_SFTP_Log_Details.txt
Is there any way to overwrite the existing log file?
To disable session log file appending in WinSCP scripting, set Logging\LogFileAppend raw configuration option:
/log=... /rawconfig Logging\LogFileAppend=0 ...
Related
I am using SQL Server Agent to run a few scripts regularly of type CmdExec with the following format:
"Absolute path to RScript.exe" "Absolute path to script.R" > "Absolute path to log folder\logfilename.txt"
This line will work when used manually in the command prompt but won't create a log file when executed through SSMS. Anyone else have trouble dealing with SSMS or is there a problem with my line?
What also works (in the sense that a file is created) in SSMS is type nul > "Absolute path to log folder\logfilename.txt" so there is no problem with the file path or write permissions.
Not sure if this piping is possible for "normal" commands, but under Step Properties -> Advanced, you can choose to save output to file
I'm trying to run a daily taskscheduleR script that pulls data into R from an API. It works when I run it as a one time task but for some reason it won't work as a daily task. I keep getting the following error in the log file:
<HEAD><TITLE>Authorization Required</TITLE></HEAD>
<BODY BGCOLOR=white FGCOLOR=black>
<H1>Authorization Required</H1><HR>
<FONT FACE=Helvetica,Arial>
<B>Description: Authorization is required for access to this proxy</B>
</FONT>
<HR>
<!-- default Authorization Required response (401) -->
Here's the code:
library(httr)
library(jsonlite)
library(tidyverse)
library(taskscheduleR)
# Url to feed into GET function
url<-"https://urldefense.com/v3/__http://files.airnowtech.org/airnow/yesterday/daily_data_v2.dat__;!!J30X0ZrnC1oQtbA!Yh5wIss-mzbpMRXugALJoWEKLKcg1-7VmERQwcx2ESK0PZpM5NWNml5s9MVgwHr5LD1i5w$ "
# Sends request to AirNow API to get access to data
my_raw_result<-httr::GET(url)
# Retrieve contents of a request
my_content<-httr::content(my_raw_result,as="text")
# Parse content into a dataframe
my_content_from_delim <- my_content %>% textConnection %>% readLines %>% read.delim(text = ., sep = "|",header = FALSE)
head(my_content_from_delim)
I have been using the Rstudio add-in to create the task.
If you are trying to access this on a work computer, you may need to allow downloads from the url link. Open a browser, paste that url, click 'allow downloads', run the script.
I am not sure whether the solution I will offer will work for you, but it won't harm to try. If the problem related to the task scheduler, the following solution might work. However, if the problem of authorization issues, you may need to get some IT help from your workplace.
For the task scheduler issue, you can directly send your script to the windows task scheduler with a batch file and create a schedule for it.
To make it easy, you can use the following code. First, open a new folder and copy-paste your R script there. To run the following code, you should call you R script as My Script.r.
Then, in the same folder, create a batch file with the following codes. To create a batch file, you should copy the following code into a Notepad and save it as Run R Script.bat in the same folder.
cd %~dp0
"C:\PROGRA~1\R\R-40~1.0\bin\R.exe" -e "setwd(%~dp0)" CMD BATCH --vanilla --slave "%~dp0My Script.r" Log.txt
Here, cd %~dp0 will set the directory for the windows batch to the folder you run this batch. "C:\PROGRA~1\R\R-40~1.0\bin\R.exe" will specify your R.exe. You may need to change the path based on your system files.
-e "setwd(%~dp0)" will set the directory of R to the same folder in which the batch and script will be run.
"%~dp0My Script.r" Log.txt will define R script pathname and the log file for the batch.
Second, to create a daily schedule, we are going to create another batch file. To do so, copy and paste the following codes into a notepad and save as Daily Schedule.bat.
When you click the Daily Schedule.bat, it will create a daily task and run for the first time in one minute, and every day it will repeat itself at the same time when you first run this batch.
#echo off
for /F "tokens=1*" %%A in ('
powershell -NoP -C "(Get-Date).AddMinutes(1).ToString('MM/dd/yyyy HH:mm:ss')"
') do (
Set "MyDate=%%A"
set "MyTime=%%B"
)
::Execute path to bat path
cd %~dp0
::Create Task
SchTasks /Create /SC DAILY /TN "MY R TASK" /TR "%~dp0Run R Script.bat" /sd %MyDate% /st %MyTime%
This code will create a task called as "MY R TASK". To see whether it is scheduled, you can run the following codes on the windows prompt: taskschd.msc. This will open your task scheduler, and you can find your task there. If you want to modify or delete, you can use this task scheduler program; it has a nice GUI and easy to navigate.
For more details about the Task scheduler syntax, see the following link
If you have any questions, let me know.
I am trying to use lua to access redis values from nginx. When i execute lua files on command line there everything is ok i am able to read and write values to redis. But i when try to execute the same files from nginx by accessing a location in which access_by_lua directive is written the following error logged in error log file
no field package.preload['socket']
no file '/home/sivag/redis/redis-lua/src/socket.lua'
no file 'src/socket.lua'
no file '/home/sivag/lua/socket.lua'
no file '/opt/openresty/lualib/socket.so'
no file './socket.so'
no file '/usr/local/lib/lua/5.1/socket.so'
no file '/opt/openresty/luajit/lib/lua/5.1/socket.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
What is the reason for this and how can i resolve this?
In my case I just needed to install the lua-socket package, as the socket library is not built into the default Lua installation like it is in some other languages.
You get this error because your code executes the command require("socket")
This command will search for a file with that name in several directories. If successful the content will be executed as Lua code. If it is not successful you'll end up with your error message.
In order to fix this you have to add the path containing the file either to the system variable LUA_PATH or you have to add it to the global table package.path befor you require the file.
Lua will replace ? with the name you give to require()
For example
package.path = package.path .. ";" .. thisPathContainsTheLuaFile .. "?.lua"
Please read:
http://www.lua.org/manual/5.3/manual.html#pdf-require
https://www.lua.org/pil/8.1.html
My requirement is used to create a ftp batch script to transfer files from Unix to Windows through the WinSCP command line. So, I pass file name to the script and file is transferred from Unix to Windows. However, when I want to transfer multiple files, the challenge here is to take all the file names from the user and run the WinSCP command to get all the files. How to loop the input for the different file names and construct the WinSCP command for the same?
Can someone help me with the approach as I am new to batch scripting?
Sample command to transfer a single file
call C:\Progra~2\WinSCP\WinSCP.exe /console /timeout="120" /command "option batch continue" "option confirm off" "open sftp://%userid%:%passw%#%host%" "get %/file/filename.txt%" "exit"
Sample command to transfer a multiple files
call C:\Progra~2\WinSCP\WinSCP.exe /console /timeout="120" /command "option batch continue" "option confirm off" "open sftp://%userid%:%passw%#%host%" "get %/file/filename.txt%" "get %/file/filename2.txt%" "get %/file/filename3.txt%" "exit"
In this case you do not have to take multiple inputs at all. The WinSCP command get can take multiple source files as arguments. You just have to use the target path as the last argument. Use the .\ to download to the current working directory (what is a default, when using a single argument only, just as in your example).
So you can prompt user only once to enter a space-separated list of files to download
set /p "list=Enter space separated list of files to download: "
winscp.com /command ^
"option batch continue" ^
"option confirm off" ^
"open sftp://%userid%:%passw%#%host%" ^
"get %list% .\" ^
"exit"
Side notes:
When running WinSCP from a batch file, use the winscp.com instead of the winscp.exe to avoid additional console window opening for WinSCP.
The command-line parameter /timeout=120 won't apply to sessions opened using the open command in the script. Use the -timeout=120 switch of the the open command:
open sftp://%userid%:%passw%#%host% -timeout=120
No point in using the call command to run WinSCP
I am assuming you are going to prompt the user input manually in the console. This will prompt for the user input repeatedly until it sees a dot .
#echo off
setlocal enabledelayedexpansion
:prompt
set /p "input=Enter the filename:"
if "!input!"=="." (
goto :begin ) else (
set input_all=!input_old! "!input!"
set input_old=!input_all!
goto :prompt
)
:begin
echo consolidated_input=!input_all!
Add your winscp command line after the label :begin
tested sample-
D:\Scripts>draft.bat
Enter the filename:c:\sample\test1.txt
Enter the filename:c:\sample\test2.log
Enter the filename:c:\sample\test3.ini
Enter the filename:.
consolidated_input= "c:\sample\test1.txt" "c:\sample\test2.log" "c:\sample\test3.ini"
Cheers, G
how do i open a file csv ? with the last command here vi
it open it the command prompt, but how do i open it on csv file normarlly
without open it on the command prompt?
[#dc1-ora rci]$ ls
backup diamond20130306.csv
diamond2012_04_30_dev.csv diamond_points_20120820.csv
diamond20120801.csv diamond_points_20120827.csv
diamond20120802.csv diamond_points_20120828.csv
diamond20120803.csv diamond_points_20121217.csv
diamond20120804.csv diamond_points_20130129.csv
diamond20120806.csv diamond_points_20130130.csv
diamond20120807.csv diamond_points_20130205.csv
diamond20120808.csv diamond_points_20130306.csv
diamond20120828.csv diamond_points_20130326.csv
diamond20120906.csv diamond_points_20130410.csv
diamond20121025.csv diamond_rental_20121219.csv
diamond20121029.csv diamond_rental_20121220.csv
diamond20121218.csv diamond_rental_20121221.csv
diamond20130128.csv ilx_final_lead_merge.csv
diamond20130129.csv test_diamond20120820.csv
diamond20130130.csv test_diamond20120827.csv
diamond20130131.csv test_diamond20120828.csv
diamond20130205.csv test.txt
diamond20130219.csv THH_RCT_RCI_EDM_FILE_01_28_13.csv
[#dc1-ora rci]$ vi test_diamond20120820.c
sv
( opens file here on the command prompt)
On windows/cmd you should do:
start notepad++ test_diamond20120820.csv
in your case:
start Excel.exe test_diamond20120820.csv
or for the default application associated with it use :
start test_diamond20120820.csv
(didn't test I am using linux maybe I will test it later if I reboot)
But I suspect you don't mean command prompt but a linux terminal (because of your tags):
you can use any of those:
gedit test_diamond20120820.csv &
nedit test_diamond20120820.csv &
etc depending on the programs you have installed
or for the default application associated with it use :
xdg-open test_diamond20120820.csv
if you are remotely logged in using ssh make sure you have X enabled