.bat file not working - windows

I have to call two bat files.
One name cbpp_job and other upload.bat.
In first .bat files, I have called cbppservice.exe and after that I have call upload.bat.
cbpp_job.bat
call d:\csdb_exe\CBPPService.exe
call ftp -n -s:"d:\csdb\Success\upload.bat" xxxx.produrl.com
upload.bat
user XXXXXX
XXXXXXXXX
PUT ZA1P.FTP.CBPP.INTRFACE.GRP(+1) 'ZA1P.FTP.CBPP.INTRFACE.GRP(+1)'
BYE
EXIT
But when I call csdb_job through command prompt it works well. When I scheduled it in task scheduler it only calls cbppservice.exe and it is not doing the ftp.
The operating System is windows server 2008.

If your event viewer doesn't show you why your script is failing, Try modifying cbpp_job.bat to redirect stderr to a log file.
(
d:\csdb_exe\CBPPService.exe
ftp -n -s:"d:\csdb\Success\upload.bat" xxxx.produrl.com
) 2>"c:\csdbtask.log"
Maybe that'll help you figure out why task scheduler is failing.

Related

INCRON Event Script/Command Not Running

I upload a file from a bike computer to my PC via Dropbox (bike computer->Dropbox->my PC) and want to start a Python program when this happens. Today, I have a CRON entry that runs every 5 minutes looking for a file but I want this process to be triggered when the file is uploaded.
I have installed INCRON and defined an event table to test that this will work when a file is uploaded. The event table for this test (and for my experience):
/home/dave/Dropbox/Test/ IN_CLOSE_WRITE /home/dave/Scripts/TestFileFound.sh $#
All I am trying to do here is trigger the 'TestFileFound.sh' script when a file is created in the specified folder and pass the file name to the script ($#).
I can see that the event is triggered when I create a new file in the folder:
Feb 02 15:27:16 davesdesktop incrond[561422]: PATH (/home/dave/Dropbox/Test/) FILE (TestFileFound.txt) EVENT (IN_CLOSE_WRITE)
Feb 02 15:27:16 davesdesktop incrond[561422]: (dave) CMD (/home/dave/Scripts/TestFileFound.sh TestFileFound.txt)
INCRON says the script is started but it does not execute. If I run the script from the command line, it works as expected, producing the file in /tmp and sending the email. The script:
#!/bin/bash
set -eu
# Original: V1
echo "From TestFileFound.sh: Test File '$1' from '$HOME/Dropbox/Test' was found!!!!" > /tmp/TestFileFound_Message.txt
# Send email
EMAIL="<my email address>" (Redacted)
SUBJ="Test File from '$HOME/Dropbox/Test' was found!!!!"
mail -s "$SUBJ" "$EMAIL" < /tmp/TestFileFound.txt
exit
It is marked executable:
[15:20:30 ~]$ ls -l Scripts/Test*.sh
-rwxrwxr-x 1 dave dave 312 Feb 2 15:22 Scripts/TestFileFound.sh
I do not see the file created by the 'echo' message in the /tmp folder nor do I see any emails when this script is triggered by the INCRON event.
I have various scripts and Python programs scheduled by my user CRON that successfully create emails to notify me when they have completed and I see those emails in my GMAIL inbox.
What have I not done or done incorrectly that this script is not running when triggered by INCRON?
Thanks ahead of time for any solutions or suggestions you can offer.
I have found that INCRON is working as intended but has a flaw that anything triggered by it can't access the system-wide '/tmp' directory (I do not know why since the same scripts triggered by my personal 'cron' work fine with write access to '/tmp'.)
The work around is simple - create a 'tmp' under your home folder and modify the scripts & programs triggered by INCRON to use this folder.

Monitoring changes on SFTP server with WinSCP and batch

I want to monitor our SFTP to send email to us if a file is added. For now I tried to make a condition with if/else with a batch script, but the batch environment does not accept my condition.
I am new with batch and automation, so what I tried to do is synchronise the SFTP file with a local file in first place and run a batch schedule to try to synchronise again; if it does then it is going to send na email (I did not make the script for the email at the moment and to be honest I do not know how to do so for now), if it did not synchronise then exit script.
Here is my script:
option batch on
option confirm off
open sftp://x#sftp.x/ -privatekey=privateKey.ppk -hostkey="ssh-rsa 2048 x"
option transfer binary
if synchronize local "C:\Users\Administrateur\Desktop\x\x" "/x/x/rx" (
ECHO nouveau fichier ajouter au repertoir
)
else (ECHO aucun nouveau fichier exit
)
Here is the error:
Commande inconnue 'if'.
Add -preview switch to your synchronize command to make it only check for changes, instead of actually synchronizing the files.
Add option failonnomatch on to your script to make the synchronize command report no differences as an error.
option failonnomatch on
synchronize -preview local "C:\Users\Administrateur\Desktop\x\x" "/x/x/rx"
In the actual batch file, check WinSCP exit code to determine, if there are any differences or not. Something like this:
winscp.com /script=script.txt /log=script.log
if errorlevel 1 (
echo Nothing to synchronize or other problem
) else (
echo There are files to synchronize
)
If you want to send an email, see WinSCP guide for Emailing script results.

How to redirect Windows cmd output to a text file?

I am trying to monitor the cmd output of a certain executable .exe and use it for another process running at the same time.
The problem is that all cmd redirecting functions ( '>','>>','<' and '|') would only redirect the output after a successful return of the last command.
What I wanted to do is to generate some kind of streaming log of my cmd.
You can run in your process in background by using
start /b something.exe > somefile.txt
Windows 20H2: Redirection works fine when logged in as true administrator but will NOT work when logged in as a created administrative user. I have used it for years to redirect the output of a multi target backup system using Hobo copy to put the console output in a log file. I have never been able to get it to work successfully in Windows 10 ver 19 or 20 on a created administrative user.
You can prefix the command with "cmd /c" to start a new command prompt, and redirect the output of the command prompt:
cmd /c YOUR CODE > TextFileName.txt
Note : Use ONLY single greater than (>)
Since the output of cmd is going to TextFileName.txt.
Whereas this misses the error output, so you are not able to see : Request to UnKnown timed-out for each failed address.

Jenkins - Execute Shell Build Step Not Working

I'm trying to create a job in Jenkins that will execute a simple shell script. However, it seems that Jenkins isn't actually doing anything with my script. No matter what value I put into the Execute Shell Command section, Jenkins always says that it passes. Even if I put in a bogus filename like "RandomBogusFilename.sh" it'll say the job was a success.
Can anyone point out what I'm doing wrong and how I can get Jenkins to actually use my shell script?
The shell script, the job config, and the console output are all shown below. I'm currently trying to do this on a Windows Server 2008 R2 Standard machine.
Thanks.
My .sh file
File Name: surveyToolRequest.sh
File Location: /jobs/Jeff Shell Script Test/workspace
Description:
Hit a web address and retrieve the HTTP Response. Then print out the HTTP Response.
#!/bin/bash
response_code=$(curl -s -o /dev/null -w "%{http_code}" http://SOME-WEBSITE.COM)
echo "The response code is " $response_code
My Jenkins Job Config
Jenkins Console Output
I played with this and found that it worked if I specified the path to the script. If the script is in your job's workspace directory,
./surveyToolRequest.sh
should work as Jenkins looks for files relative to the root of the workspace.
It's more common to just put the contents of the script file directory into the job configuration; that way you can see what the job is doing and you'll avoid problems like this one.
You should use run "Execute windows batch command" and not "Execute Shell"

automating telnet session in windows is not working

Hi I have created a file temp.txt with the the content as below
root
root123
ls -lrt
exit
and then I am excuting the below command in dos
c:\>telnet machine_ip < temp.txt
Output is
Welcome to the Microsoft Telnet client
Escape character is 'ctrl+]'
C:\> Telnet>
How to automate the telnet session in windows with this method. I cant use any other exe(putty.exe) or tool to do this. I have to use the available things in windows xp. Suggest me also if any other way is there.
I am not sure if you can pass the username and password to telnet program from a text file.
You can create a vbs script and use sendkeys to pass username and password.
Create a batch script which starts a telnet session of a box and then call the vbs script from the batch script using
CSCRIPT //NoLogo //B "C:\Path\to\Script>script.vbs"
Hope this helps!

Resources