How to deploy bat file within remote dileserver through jenkins - batch-file

I have installed Jenkins at 1.1.1.01 Ipaddress, and a bat file does exist at remote fileserver 1.1.1.02 Ipaddress (that may differ by user, because I will give Ipaddress as a parameter).
Can I deploy that bat file through Jenkins pipeline?

You need first to check, independently of Jenkins, if you can access 1.1.1.02 (or any other remote server IPs) from 1.1.1.01, assuming 1.1.1.01 is the server executing your job.
If, from 1.1.1.01, you can SSH for instance to 1.1.1.02, or scp 1.1.1.02, then you can copy a file (like your bat file), from 1.1.1.01 to 1.1.1.02 or vice-versa.

Related

How to change remote directory location to a path out of SFTP root in WinSCP

I am SQL DBA using WinSCP command line in SSIS package to download backup file from SFTP server.
My default remote directory on the server is C:\sftp_root, which I can see in WinSCP as /. But my backup files is at D:\Backup folder. I can't keep my backup file on C drive as it's having space issue.
I am using below command line using WinSCP.com in my SSIS package to download the backup file. When trying to change my remote directory, I am getting an error "No Such file exists".
/log=D:\DBA\winscp.log /console /command "option batch abort" "option
confirm off" "open sftp://sftp_dba:Password#2.2.2.0:22
-hostkey=""ssh-rsa 2000 2s:2g:44:12:56:ws:ss:as""" "cd /D:\Backup" "get *.bak D:\Backups\" "rm *.bak" "exit"
First of all I am wondering if it is possible to change remote directory path in the above command line? If yes, please help me with the syntax.
I am stuck here and need experts help.
Thanks in advance.
What path(s) on the server file system you can access with SFTP protocol is a matter of configuration of the SFTP server.
If the SFTP server is configured to map only C:\sftp_root to SFTP root path / (aka to jail your account to C:\sftp_root), there's no magical way for you to circumvent that (escape the jail).
You have to reconfigure the SFTP server to allow an access to a different path.
E.g. you can map the D:\Backup to /backup.

SQL Agent Job to run .bat with gsutil rsync

I am trying to create a scheduled SQL Agent Job that executes a .bat file with a gsutil rsync command to synchronize a local folder with a Google Cloud Bucket. The task runs without an error, but does not finish or actually perform the rsync command.
I can however manually run the .bat file with success as the root user, as I have a key handshake with the GCP service account. I can also successfully execute other non-gsutil .bat files from the SQL Agent Job, as I have created credentials and proxy to run as the root user
The .bat file looks like this :
gsutil rsync -r G:\MyBackupFolder gs://my-coldline-storage-bucket
and I am running the SQL Agent step as type Operating system (CmdExec)

Executing FART.exe (find and replace text) commands on remote server through SSH

I'm executing a batch file on a remote server from our build server (Jenkins) through SSH. The batch file uses fart.exe commands to find and replace text. I have placed the fart.exe in C:\Windows\System32 and I'm invoking it as C:\windows\system32\fart.exe in the batch file.
The command works perfectly fine oin the remote server, but when invoking through SSH I get an error in the Jenkins log as:
'"C:\windows\system32\fart.exe"' is not recognized as internal or external command.
This is the only error I'm getting and the other commands successfully execute in the batch script. Both of the servers are Windows Server 2012 R2.
I tried adding the path to system variable but it didn't work.
This is how the Fart.exe is used in the batch script.
for /R "%BACKUP_SOURCE%" %%G in (%ConfigFile%) do (
"C:\windows\system32\fart.exe" "%%G" %PlaceHolder% %AppPath%
)
Invoking From Jenkins
I don't think the way i invoke the batch script do matter, because it is done trough the Jenkins SSH plugin. The batch script get invoked successfully. The error i get is from when executing the Fart.exe
I tried invoking a different command of an exe located in the same path, and that is successfully invoked. so i guess the issue is isolated to FART.EXE.

Remotely executed batch file calling an external executable

I am trying to call a .cmd file on a remote server (which works) and from that .cmd file call an external executable on the remote server to compress some files. This used to work in an older environment (remote server was a 2003 machine), but we are migrating to a new 2012r2 server and now I am getting a path not found error. I know the path's are correct, because locally I can run all of these commands without any problems. Let me lay it out a bit cleaner:
Calling server:
I use the following command line to call the script which lives on the remote server:
\\server1\path1a\path1b\myscript.cmd \\server1\path2a\path2b\
Remote server:
On here the contents of the "myscript.cmd" file is:
#echo off
e:\utils\gzip.exe -N -3 -a %1\p*
if %errorlevel% GTR 0 goto zipfail
echo ZIP WORKED!
exit
:zipfail
echo ZIP FAILED with error: %errorlevel%
exit
As you can see I am passing in a parameter to where the source files to be zipped live. The account on the calling server that I using has Full Access (both file and share level) to the directory where the .cmd file lives, as well as to the local path e:\utils where on the remote server the gzip utility lives. I can run this from the remote server and it all works normally, but when I try to call it from a remote machine I get back and error of "the system cannot fine the path specified". I've confirmed that the issue is not the "c:\utils\gzip.exe" path, in that if that is missing or incorrect I get a different error which states that it cannot find the gzip utility. That means the issue is getting gzip to launch and have it access the remote path where the files are to be compressed.
(BTW, I have tried putting gzip to the same path where the .cmd file lives, same results.)
Any ideas? Is this some new security restriction on 2012 whereby a remote executing script is unable/not allowed to access remote executables?
Paul was right - its been too long since I have worked with batch files that I am starting to forget the basics... grrrr!
The path (and called executable) was missing on the calling (aka machine running the script). Once I fixed that its was working great!

Batch Remote Copy

I am interested in creating a batch file (ran on my computer) that can copy files from a server location to a computer connected to my network.
Something like:
xcopy //SERVER/FILE CONNECTEDCOMPUTER
It would be fine if I had to run the batch from the server or something like that. I just want to be able to remotely send a file to a connected computer.
As long as you have access to the files (the files are on a share you can read from), XCOPY should work fine. If you map a share to a local drive letter, you have the normal syntax for XCOPY as if you copy locally.
Without a mapped drive, simply use something like this to copy from server to C:\ :
XCOPY \SERVERNAME\SHARENAME\FILEORDIRECTORIES C:\
I am not sure I understand your aversion for sharing if what you want to do is share files... but you could install an ssh server for Windows on the remote machine, such as this - Bitvise
Then all you need to do is use
winscp file remote:
or
pscp file remote:
if you go the putty route.
Or you could install the free Filezilla FTP Server on the remote machine and send your file via FTP.

Resources