angelshark
MIS
Hello,
I would like to convert the following Windows batch file into a Perl script:
1. set logs_dir=E:\Program Files\nsr\logs
2. set savegrp_tmp="%logs_dir%\savegrp_tmp.log"
3. nsrlog -f %savegrp_tmp%
4. for /F "tokens=8 delims==, " %%a in ('findstr level %savegrp_tmp%') do set level=%%a
5. if %level% EQU skip goto end
6. for /F "tokens=2-4 delims=/ " %%a in ('date /t') do set date=%%b-%%a-%%c
7. for /F "tokens=1-2 delims=: " %%a in ('time /t') do set time=%%a_%%b
8. for /F "tokens=8" %%a in ('findstr Savegroup %savegrp_tmp%') do set group=%%a
9. set group_dir="%logs_dir%\savegroups\%group%"
10. set report=%group_dir%\report_%date%_%time%.log
11. copy %savegrp_tmp% %report%
12. :end
13. type %savegrp_tmp% >> "%logs_dir%\savegrp.log"
14. del %savegrp_tmp%
Here’s a description of what each line of the script does:
1. set the variable logs_dir
2. set the variable savegrp_tmp
3. create a text file with the file name and path as defined in the previous variables
4. search for the word next to “level” and store it in a variable
5. if that word equals “skip”, end the script.
6. store the date in a variable
7. store the time in a variable
8. search for the word next to “Savegroup” and store it in a variable
9. set the variable group_dir
10. set the variable report
11. copy the text file into another location
12. continue from here condition in line 5 is true
13. append the text file to another file
14. delete the file
I would like to add a feature to the script which apparently isn’t possible using batch files. Before the 11th line I want to check if the destination directory exists and if it does not, I want it to be created.
Thanks for all your help.
I would like to convert the following Windows batch file into a Perl script:
1. set logs_dir=E:\Program Files\nsr\logs
2. set savegrp_tmp="%logs_dir%\savegrp_tmp.log"
3. nsrlog -f %savegrp_tmp%
4. for /F "tokens=8 delims==, " %%a in ('findstr level %savegrp_tmp%') do set level=%%a
5. if %level% EQU skip goto end
6. for /F "tokens=2-4 delims=/ " %%a in ('date /t') do set date=%%b-%%a-%%c
7. for /F "tokens=1-2 delims=: " %%a in ('time /t') do set time=%%a_%%b
8. for /F "tokens=8" %%a in ('findstr Savegroup %savegrp_tmp%') do set group=%%a
9. set group_dir="%logs_dir%\savegroups\%group%"
10. set report=%group_dir%\report_%date%_%time%.log
11. copy %savegrp_tmp% %report%
12. :end
13. type %savegrp_tmp% >> "%logs_dir%\savegrp.log"
14. del %savegrp_tmp%
Here’s a description of what each line of the script does:
1. set the variable logs_dir
2. set the variable savegrp_tmp
3. create a text file with the file name and path as defined in the previous variables
4. search for the word next to “level” and store it in a variable
5. if that word equals “skip”, end the script.
6. store the date in a variable
7. store the time in a variable
8. search for the word next to “Savegroup” and store it in a variable
9. set the variable group_dir
10. set the variable report
11. copy the text file into another location
12. continue from here condition in line 5 is true
13. append the text file to another file
14. delete the file
I would like to add a feature to the script which apparently isn’t possible using batch files. Before the 11th line I want to check if the destination directory exists and if it does not, I want it to be created.
Thanks for all your help.