0

I am trying to set a crontab task to run multiple scripts / commands over night.

I created a .bat and set it to start by running a python script.. then it should sleep a few and run other commands, then sleep and then possibly run another python script; collect logs; sleep; ect..

    "C:\Python310\python.exe" "C:\Users\[name]\Desktop\Scripts\quick_test1.py" sleep 200; adb -s [IP address] shell "sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 1;sendevent /dev/input/event6 0 0 0;sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 0;sendevent /dev/input/event6 0 0 0"; sleep 30; uptime -p; sleep 10; "sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 1;sendevent /dev/input/event6 0 0 0;sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 0;sendevent /dev/input/event6 0 0 0"; sleep 10; "sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 1;sendevent /dev/input/event6 0 0 0;sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 0;sendevent /dev/input/event6 0 0 0"; sleep 10; C:\Python310\python.exe" "C:\Users\[name]\Desktop\Scripts\quick_test2.py"; sleep 10; [collect logs cmd here]; exit

Is this possible or is there another way to achieve this ? I'm using windows command prompt for now, but will be using this on a linux system later to achieve the same goal. Thank you

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Genius
  • 55
  • 6

1 Answers1

0

THIS basically will do the same thing, use call to send that cmd and wait until complete to start the next. Use a different line for each call event, and for each timeout event.. Cool!

call "C:\Python310\python.exe" "C:\Users\NAME\Desktop\Scripts\quick_test1.py" 
timeout 10 
call adb -s IP adress shell "sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 1;sendevent /dev/input/event6 0 0 0;sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 0;sendevent /dev/input/event6 0 0 0"; sleep 5; uptime -p; sleep 10; "sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 1;sendevent /dev/input/event6 0 0 0;sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 0;sendevent /dev/input/event6 0 0 0"; "sendevent/dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 1;sendevent /dev/input/event6 0 0 0;sendevent /dev/input/event6 4 4 787201;sendevent /dev/input/event6 1 240 0;sendevent /dev/input/event6 0 0 0"; exit; 
timeout 10
call "C:\Python310\python.exe" "C:\Users\NAME\Desktop\Scripts\quick_test1.py" 
timeout 10 
Genius
  • 55
  • 6
  • Please open a [command prompt](https://www.howtogeek.com/235101/), run `call /?` and read the output help. Then remove `call` from the two command lines running `python.exe` which is not a batch file and therefore `call` is useless and not needed at all. It just causes a second parsing of the command line not containing any environment variable reference which would require a second parsing. See also [How does the Windows Command Interpreter (CMD.EXE) parse scripts?](https://stackoverflow.com/questions/4094699/) – Mofi Aug 11 '22 at 17:05
  • What is the purpose of `timeout 10` better written as `%SystemRoot%\System32\timeout.exe /T 10 /NOBREAK >nul`? The Windows Command Processor `cmd.exe` always waits for self-termination of a started executable on processing a batch file. So the second command line is never executed before started `python.exe` terminated itself after the Python script execution finished. – Mofi Aug 11 '22 at 17:08
  • Run in a command prompt window `where adb` or `%SystemRoot%\System32\where.exe adb` and look on the output. Is a file with name `adb` found? Yes, most likely. What is its file extension? Is it `.exe` or `.com`? Yes, then command `call` is also useless on this command line and the executable `adb` is specified better with at least its file extension and best with its fully qualified file name. Otherwise on `adb` is a batch file with file extension `.bat` or `.cmd`, append the file extension on calling the batch file `adb`. – Mofi Aug 11 '22 at 17:11
  • The folder `Desktop` should contain only shortcut files with file extension `.lnk` and not other files and folders. So better move the folder `Scripts` from `%USERPROFILE%\Desktop` to directory `%USERPROFILE%` by running in a command prompt window `move "%USERPROFILE%\Desktop\Scripts" "%USERPROFILE%\"` and use twice in the batch file `"%USERPROFILE%\Scripts\quick_test1.py"`. You can right click in Windows File Explorer on the folder `Scripts` in directory `%USERPROFILE%` and click in context menu in submenu __Send to__ on the item __Desktop (create shortcut)__ for a shortcut to this folder. – Mofi Aug 11 '22 at 17:15