Monday, 24 July 2023

Batch script to run perl file in linux machine | How to connect to linux in batch script and run perl file

To run a perl file placed in linux machine from batch file use "plink" utility of PuTTY in batch scripting. 

As shown below write batch script and as on execution of batch file in windows machine, the perl will be triggered in linux machine. 

PuTTY should be installed in the windows(source machine) and plink.exe should be there in the installation folder and it does the job of running perl file in linux machine. 

perlexecutioninlinux.bat

@echo off
set "destinationUser=linuxadmin"
set "destinationPassword=MyPassword#123"
set "destinationHost=11.123.4.567"
set "scriptPath=/home/linuxadmin/AutomationProject/my-perl-file.pl"

plink -pw %destinationPassword% -batch %destinationUser%@%destinationHost% "perl %scriptPath%"

timeout /t 5 /nobreak
exit

I hope you find this useful! If you like it, pls do subscribe my YouTube channel for automation or tech updates.

No comments:

Post a Comment