Solved

Script with return code.

Posted on 2008-10-28
11
840 Views
Last Modified: 2008-11-12
Hello,

I have made a script (and i don`t know the first thing about scripting).
The script gives a program on a remote server the command to make a snapshot and then mounts the snapshot on the local server.

The script works as followed:

First it starts another script on a remote server with PSexec.exe
This little script generates a file on a share.
Then the main script gets the filename and based on that filename it runs a program called asmcli.exe

The scripts works without a problem when i run it from the command prompt.

The problem is the script is run within backupserver software.
This software wants a return code. But my script already gives a return code after the psexec finishes.
So my backup software things that the script has finished and goes to the next fase of the backup software.

So how do i supress the first return code and get a return code (0) after the script is really finished.

Thanks alot for your help!

Regards,

Hans


@echo off

setlocal
 

@REM *** START: Turns logging on ***

if "%~1" == "NOWLOGGING" goto NowLogging

    set SchedulesLogFile=%TEMP%\%~n0 - %date:/=-% %time::=_%.txt

    set SchedulesLogFile=%TEMP%\%~n0 - %RANDOM%.txt

    set SchedulesLogFile=%TEMP%\%~n0.txt

    %0 "NOWLOGGING" > "%SchedulesLogFile%" 2>&1

    goto :EOF

:NowLogging

@REM *** END: Turns logging on ***
 
 

@rem Guts of batch file...

echo [%date% %time%] starting...

echo *** start of actual batch file...
 

e:\Backup_Scripts\psexec.exe \\itcdc02 c:\backup_scripts\make_snap.bat
 

f:

cd "F:\Backup_Documents\itcdc02\Psv{28a09060-1ff0-cae7-4f8d-94440100f087;65536}\"

for %%x in (*.bcd) do set filename=%%x
 

"C:\Program Files\EqualLogic\bin\asmcli.exe" -mount -document="F:\Backup_Documents\itcdc02\Psv{28a09060-1ff0-cae7-4f8d-94440100f087;65536}\%filename%" -location="e:\mount_path\itcdc02\"
 

echo *** end of actual batch file...

echo [%date% %time%] ending...

Open in new window

0
Comment
Question by:Hans de Jongh
  • 5
  • 3
  • 3
11 Comments
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Hi, Hans.

Use the Exit command to end the batch file and return a value.  Something like this:

Exit 0

See this page for more details: http://www.robvanderwoude.com/exit.html
0
 

Author Comment

by:Hans de Jongh
Comment Utility
Hi,

That still doenst supress my first return code..
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
If the backup software is calling the batch file you posted, then I don't know how it can move on until the entire batch file has finished.  Are you sure the return code is the issue and that the problem isn't a result of the batch file continuing to run instead of waiting for the PSEXEC command to finish?
0
 

Author Comment

by:Hans de Jongh
Comment Utility
no i`m not sure about that, how can i check that?
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
I don't remember the command syntax for PSEXEC.  Look and see if there's a parameter that waits for the remote command to finish before moving on.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Hans de Jongh
Comment Utility
well it waits by default on the finish. (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) there is an option to override this.

I dont think that`s the problem here is my log output:


[di 28-10-2008 18:58:22,36] starting...
*** start of actual batch file...

PsExec v1.94 - Execute processes remotely
Copyright (C) 2001-2008 Mark Russinovich
Sysinternals - www.sysinternals.com


C:\WINDOWS\system32>"C:\Program Files\EqualLogic\bin\ASMCLI.exe" -smart -email -volume=D:\ -shadowtype=Transportable -backuptype=full -snapshottype=Snapshot

EqualLogic VSS Administrator successfully created the smart copy.
Connecting to itcdc02...
                                                                             


Starting PsExec service on itcdc02...
                                                                             


Connecting with PsExec service on itcdc02...
                                                                           


Starting c:\backup_scripts\make_snap.bat on itcdc02...
                                                                             


c:\backup_scripts\make_snap.bat exited on itcdc02 with error code 0.
ASMCLI tried to mount 1 snapshots:
     Volumes mounted successfully:
     e:\mount_path\itcdc02\;

*** end of actual batch file...
[di 28-10-2008 18:58:46,75] ending...

0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
Hi, from the above, I'm guessing your PSExec command looks something like this:

psexec \\computername -accepteula -u domain\user -p pass C:\temp\MyBatch.bat

Let's try making it wait for the batch file to complete....

psexec \\computername -accepteula -u domain\user -p pass cmd /c start /wait C:\temp\MyBatch.bat

Similarly, in the batch file itself, wherever it runs an exe, try adding
start /wait

to the front of each command.

Regards,

Rob.
0
 

Author Comment

by:Hans de Jongh
Comment Utility
thanks but that doenst work either...

the problem is that the make_snap.bat also gives back a return code. So the program who is running the mail script sees an return code and thinks that the script is finished..
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
Let me try and get this straight....it is confusing me somewhat....

Your backup software executes the batch file you posted with the original question.
That batch file has this part in it:
'===============================
e:\Backup_Scripts\psexec.exe \\itcdc02 c:\backup_scripts\make_snap.bat
 
f:
cd "F:\Backup_Documents\itcdc02\Psv{28a09060-1ff0-cae7-4f8d-94440100f087;65536}\"
for %%x in (*.bcd) do set filename=%%x
'===============================

and what you are saying is that your backup software catches the return code from PSExec *before* that batch script executes the f: command and the cd "F:\Backup...." commands.....

Is that right?

That would seem really odd! That would mean that the software is monitoring for a return code from anything....

Unless I have it wrong....

Rob.
0
 

Author Comment

by:Hans de Jongh
Comment Utility
i think your right.

This is the log of the backupsoftware, it already stops after 1 second.. Then the first part isnt finished yet.. Is there a way to see the script run?


5336 18b8 10/30 09:30:42 ### ::main() - startPrePostCmd Started.
5336 18b8 10/30 09:30:42 ### ::main() - jobId 385 - before init jobobject
5336 18b8 10/30 09:30:42 385 JM Client  CVBkpJobClient::init(): Initializing job object with token [385:3:1].
5336 18b8 10/30 09:30:42 ### CVJobCtrlLog::registerProcess(): successfuly created file [C:\Program Files\CommVault\Galaxy\Base\JobControl\5.336]
5336 18b8 10/30 09:30:42 ### ::main() - jobId 385 - restoreTaskId = 0
5336 18b8 10/30 09:30:42 ### ::getBackupCmdAndMachine() - jobId 385 - before construct application id
5336 18b8 10/30 09:30:43 ### ::getBackupCmdAndMachine() - appTypeId = 42
5336 18b8 10/30 09:30:43 ### ::getBackupCmdAndMachine() - jobId 385 - symbolic AppId = 2:40
5336 18b8 10/30 09:30:43 ### ::getBackupCmdAndMachine() - jobId 385 - prePostId = 1
5336 18b8 10/30 09:30:43 ### ::getBackupCmdAndMachine() - jobId 385 - preifind cmd = F:\Backup_Scripts\Multiflexx\prebackup.bat
5336 18b8 10/30 09:30:43 ### ::main() - jobId 385 - commandPath = F:\Backup_Scripts\xxxxxxx\prebackup.bat
5336 18b8 10/30 09:30:43 385 ::main() - jobId 385 - before execute cmd
5336 18b8 10/30 09:30:43 385 ::main() - jobId 385 - Use Local System Acct.
5336 18b8 10/30 09:30:43 385 ::main() - jobId 385 - remoteexename = [F:\Backup_Scripts\xxxxxxxx\prebackup.bat]
5336 18b8 10/30 09:30:43 385 ::main() - jobId 385 - args = [ -bkplevel 2 -attempt 1 -job 385]
5336 18b8 10/30 09:30:43 385 ::main() - jobId 385 - executeRemoteCommandAsUser on itcbck01.itc.local*itcbck01*8400*8402 (platform 4)
5336 18b8 10/30 09:30:43 385 ::main() - jobId 385 - Got batch file exit code: 0
5336 18b8 10/30 09:30:43 385 ::exitHere() - jobId 385 - startPrePostCmd Completed.
5336 18b8 10/30 09:30:43 385 BKP CALLED COMPLETE (PHASE Status::SUCCESS), 385. Token [385:3:1]
5336 18b8 10/30 09:30:46 385 ::exitHere() - jobId 385 - startPrePostCmd Terminating Event.
5336 1a5c 10/30 09:30:46 385 CVJobCtrlLog::unregisterProcess(): successfuly removed file [C:\Program Files\CommVault\Galaxy\Base\JobControl\5.336]
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
Comment Utility
Hmmmm, I'm not sure....I've browsed through these:
http://documentation.commvault.com/commvault/release_7_0_0/books_online_1/english_us/features/pre_post/prepost_process_how_to.htm
http://documentation.commvault.com/commvault/release_7_0_0/books_online_1/english_us/features/pre_post/prepost_process.htm

but they still state the the software should wait for the batch file's return code.

To try and get an idea on whether the pre process is running to it's end, see where you have lines such as
echo [%date% %time%] starting...
echo *** start of actual batch file...

you could add lines such as
echo [%date% %time%] starting... >> C:\Temp\Pre_Log.txt
echo *** start of actual batch file... >> C:\Temp\Pre_Log.txt

and it would write to a log file as well, so you'd know whether it got that far....

Regards,

Rob.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now