AutoSys Workload Automation

Expand all | Collapse all

Multiple Dos Commands on one command line

  • 1.  Multiple Dos Commands on one command line

    Posted Aug 10, 2016 11:59 AM

    I do NOT want to use a bat file for running multiple dos commands - can that be done via one command line in Autosys:

     

    example:

     

    echo "waiting 10 seconds" & timeout /t 10 & echo "waiting done..."



  • 2.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 12:02 PM

    Multiple commands can be dangerous especially in DOS.

    Proper bat code is the way to go.

     

     

     

    Steve C.



  • 3.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 12:13 PM

    Proper, but it hides the source commands.

    If we can stack commands on one command line we do not need to create/maintain a separate library of bat files.

    Code is open to see.

     

    As we are trying not to create separate jobs just to “sleep”, way too many of them now.

     

    One command line would allow us to embed the “sleep” function via the “timeout” command then execute the next commands or script as opposed to creating just a “sleep” job.



  • 4.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 12:36 PM

    I am an ESP user not Autosys so I am not able to test with Autosys, but the example below works at the Windows command prompt.

     

    You could also make each command it's own job then have successors run depending on exit status of a command.  This would provide batch like functionality without writing a batch script.

     

    To answer your question use the ampersand as a delimiter between commands.

     

    A single ampersand & is equivalent to the semi-colon separator in bash and other shells.

     

    There is also && (or ||) which only executes the second command if the first succeeded (or failed).

     

    Environment variables tend to be evaluated on read rather than execute.

     

    You can get round this by turning on delayed expansion using: cmd /v:on /c

     

    Example to display the current time, sleep for 2 seconds and display the new time:

     

    cmd /v:on /c "echo !time! & sleep 2 & echo !time!"

    12:25:48.70
    12:25:50.72



  • 5.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 12:53 PM

    That works to stack multiple commands together.

     

    I do not have access to “sleep” so I was using “timeout /t 10 > nul”

     

    cmd /v:on /c "echo & timeout /t 10 > nul & echo !time!"

     

    but that complains as follows:

     

    ERROR: Input redirection is not supported, exiting the process immediately.



  • 6.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 01:32 PM

    Sweet

     

    Got it working  - now I don’t have to create a separate job just to “sleep” (which I don’t have) – so using “timeout 30”

    To wait 30 seconds before executing the “recycle of the apppool”

     

    Command line:

     

    cmd /v:on /c "start /wait timeout 30 & C:\windows\system32\inetsrv\appcmd recycle apppool /apppool.name:DefaultAppPool"



  • 7.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 01:19 PM

    And without proper error codes?

    Then have a sep job for each command.

    Otherwise you are asking for trouble. I am unsure what you are trying to accomplish by this..

    Proper code and error checking are tantamount to proper batch. NOT seeing the command that was run.

     

     

     

    Steve C.

     

     

    Nothing in this message is intended to constitute an electronic signature unless a specific statement to the contrary is included in this message.

     

    Confidentiality Note: This message is intended only for the person or entity to which it is addressed. It may contain confidential and/or privileged material. Any review, transmission, dissemination or other use, or taking of any action in reliance upon this message by persons or entities other than the intended recipient is prohibited and may be unlawful. If you received this message in error, please contact the sender and delete it from your computer.



  • 8.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 01:25 PM

    Command line is now working as:   (overkill on the date and time but it still waits/sleeps for 30 seconds)

     

    date /t & time /t & start /wait timeout 30 & date /t & time /t



  • 9.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 01:31 PM

    Cscript can do a sleep. So can vbscript.

     

    As well as perl etc etc etc ..

     

    Depending on what is on command line. That may not make it on my watch.

    Hacks have no place in prod. Especially if a failure wakes me up.

     

    Steve C.

     

     

    Nothing in this message is intended to constitute an electronic signature unless a specific statement to the contrary is included in this message.

     

    Confidentiality Note: This message is intended only for the person or entity to which it is addressed. It may contain confidential and/or privileged material. Any review, transmission, dissemination or other use, or taking of any action in reliance upon this message by persons or entities other than the intended recipient is prohibited and may be unlawful. If you received this message in error, please contact the sender and delete it from your computer.



  • 10.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 02:43 PM

    Speaking of hacks, here is a sneaky way to sleep in Windows:

    ping -n # 127.0.0.1 where # is the number of seconds.

     

    And here is a Powershell sleep example:

    Write-Host "hello"; Start-Sleep 5; Write-Host "world"



  • 11.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 03:10 PM

    Thanks – we tried PING before but it is kind of messy with all the network traffic introduced.

     

    I liked RickR’s solution to stuff multiple commands into one command line cmd /v:on /c

     

    wound up using this with the concatenation character = &

    to have two commands folded into one job versus creating 2 separate jobs:

     

    1 - sleep (timeout) for 10 minutes

    2 - issue the app pool recycle command

     

    cmd /v:on /c "start /wait timeout 600 & C:\windows\system32\inetsrv\appcmd recycle apppool /apppool.name:DefaultAppPool"



  • 12.  Re: Multiple Dos Commands on one command line

    Posted Aug 10, 2016 03:14 PM

    ' Program: Sleep.vbs

    ' Author: Steve Carrobis 3/26/2009

    ' Description: sleeps for X microseconds. 1000=1 second

    ' ARG: number of microseconds

    ' History: 1.0 - taken from sample code found online.

    '

    ' e.g. cscript.exe Sleep.vbs 10000

    '   sleeps for 10 seconds

    '

    '

     

    Dim Arg

    on error resume next

    MSecs = WScript.Arguments(0)

    wscript.sleep(MSecs)

    wscript.quit(0)

     

     

     

     

     

    Steve C.



  • 13.  Re: Multiple Dos Commands on one command line
    Best Answer

    Posted Aug 10, 2016 07:53 PM

    If WAAE is 11.3.x, then its very own %AUTOSYS%\bin\as_test.exe utility would do the sleep. I

     

    C:\PROGRA~2\CA\WORKLO~1>as_test -?

     

    CA WAAE Test Utility

     

    USAGE: as_test [-t Seconds] [-e Exit Code] [-c Message] [-r Message] [-x] [-?]

     

    WHERE: -t Seconds    Sleeps for given number of seconds

           -e Exit code  Exits with given argument as return code

           -c Message    Writes message to STDOUT

           -r Message    Writes message to STDERR

           -x            Returns version information

           -?            Help

     

    Cheers,

    Chandru