SSMS agent job using scp command to transfer files to sftp is going to loop and not completing - perl

Have tried different approaches to make the SSMs job working with SCP command with perl script. but the job is going into loop with out having a result.
PS : The script is working fine with running from command prompt directly.
command used in the perl script:-
$Command = "scp -i D:\File1\RS2\DataFeed\Code\PrivateKey.ppk -s $InternalFile admin#sftp.world.com:$VendorName/$DestFileName";
system command used in perl
system($command);
While running the command directly from windows cmd it is correctly placing file to the SFTP. but while running this perl script from ssms agent job it seems not working and the job is keep running without any results.
Any possible leads to the actual errors will be much appreciated
Detailed Steps :
Job in SSMS :
Step :
DataFeed.cmd
%_Debug% echo off
cd /d %0\..
pushd .
setlocal
rem -----------------------------------------------------------------
rem Localize environment
rem -----------------------------------------------------------------
if exist DataFeed_Environment.cmd (
call DataFeed_Environment.cmd
) else (
echo DataFeed_Environment.cmd not found!!!
echo
goto CmdUsage
)
rem -----------------------------------------------------------------
rem Run perl package
rem -----------------------------------------------------------------
C:\Perl\bin\perl.exe DataFeedProd1.pl
if %ERRORLEVEL% NEQ 0 goto ErrorExit
goto Exit
rem -----------------------------------------------------
rem Command Usage
rem -----------------------------------------------------
:CmdUsage
Echo ---------------------------------------------------------------------
echo.
echo DataFeed.cmd
echo Wraps the call to DataFeed.pl,
echo mails log upon errors.
echo.
echo Usage:
echo DataFeed.cmd
echo.
echo ----------------------------------
rem endlocal
rem popd
rem exit 1
rem -----------------------------------------------------------------
rem Error exit
rem -----------------------------------------------------------------
:ErrorExit
echo DataFeedProd1.pl failed !!!
echo
rem endlocal
rem popd
rem exit 1
rem -----------------------------------------------------------------
rem Exit
rem -----------------------------------------------------------------
rem endlocal
rem popd
:Exit
rem exit 0
sub CopyDataFeedFileToSftp{
my ($DataFeedFileInternal, $DataFeedVendorName,$DataFeedFileName) = #_;
my($DestFileName)=$DataFeedFileName.".zip";
my($Command);
my($RetValue) = 1;
$Command = "C:\\Users\\hprasu\\Downloads\\OpenSSH-Win64\\scp.exe -i D:\\File1\\RS2\\DataFeed\\Code\\PrivateKey.ppk -s $DataFeedFileInternal a_Tne\#nasftp\.egencia.com:$DataFeedVendorName/$DestFileName";
$RetVal = &CallSystem($Command);
if ($RetVal == 0) {
&AppendFileToLog($TempFile);
&ErrorExit("Unable to copy data feed file using SCP command:\n".$Command);
}
}
The above perl method is executing the System command

You should:
have full path to perl.exe and your perl script in job's command
escape all special characters in interpolated strings for Perl and
use full path for scp command since
operating system don't know where scp.exe is located (until it in the $PATH):
check filesystem permissions for all files in the command and perl script. Job should has access those files.
So command would be
$Command = "full_path\\scp.exe -i D:\\File1\\RS2\\DataFeed\\Code\\PrivateKey.ppk -s $InternalFile admin\#sftp.world.com:$VendorName/$DestFileName";
Read this:
https://www.geeksforgeeks.org/perl-quoted-interpolated-and-escaped-strings/

Related

Batch File - Format Date/Time For Logging

I wrote a script that's executed by Task Scheduler every night at 23:00 to have NAS01 power on NAS02 if it's not already on, execute a GoodSync job to backup NAS01, and shutdown NAS02 upon completion. The script isn't pretty, but it does the job. The issue that I have is the timestamps. I set variables to set the format for the date and time, however, this will just reference the timestamp of the variable for the entire script. How do I keep the formatting, but be able to get the date and time at each point it's called?
As you can see from the script, there's a date/time format for the log filename, and a date/time format for the logging within the log file. What happens in my formatting:
Forced 24H time
Leading space in the hour is replaced with a '0' (IE " 6:30" becomes "06:30")
Time fomatting is HHMM for filename and HH:MM:SS for logging
Date formatting is YYYYMMDD for filename and YYYY/MM/DD for logging
Script:
#ECHO off
REM Change CMD window color and size.
color 37
mode 180,50
REM ### Set variables
SET IPADDRESS1=11.11.11.20
SET IPADDRESS2=10.0.3.1
SET HH=%time:~-11,2%
SET MM=%time:~-8,2%
SET SS=%time:~-5,2%
SET NAMETIMESTR=%HH: =0%%MM%
SET LOGTIMESTR=%HH: =0%:%MM%:%SS%
SET MYDATE=%DATE:~4,10%
SET NAMEDATESTR=%MYDATE:~6,4%%MYDATE:~0,2%%MYDATE:~3,2%
SET LOGDATESTR=%MYDATE:~6,4%/%MYDATE:~0,2%/%MYDATE:~3,2%
SET LOGFILE=C:\!SCRIPTS\logs\7xNAS02-GSync-%NAMEDATESTR%_%NAMETIMESTR%.txt
:START
REM ### Checks IF 7xNAS02 is online. IF not, power it on.
ECHO ################################################################################################################################ >> %LOGFILE%
ECHO %LOGDATESTR% %LOGTIMESTR% EXECUTING GSYNC SCRIPT >> %LOGFILE%
ECHO ################################################################################################################################ >> %LOGFILE%
ECHO.
ECHO This is an automated script to backup the storage array on 7xNAS01 onto 7xNAS02.
ECHO IF 7xNAS02 isn't powered on, the script will boot 7xNAS02, wait for it to come online,
ECHO and then execute the "STORAGE" backup job in GoodSync.
ECHO.
ECHO %LOGDATESTR% %LOGTIMESTR% Checking power status of 7xNAS02... >> %LOGFILE%
ECHO Checking power status of 7xNAS02...
ECHO.
ping -n 1 %ipaddress1% | findstr TTL && GOTO ALREADY_ON
ping -n 1 %ipaddress1% | findstr TTL || GOTO POWER_ON
:ALREADY_ON
REM Sets variable to dictate that the server was already on before executing the script.
ECHO.
ECHO %LOGDATESTR% %LOGTIMESTR% 7xNAS02 is already powered on and available. >> %LOGFILE%
ECHO 7xNAS02 is already powered on and available.
ECHO.
SET previously_off=1
GOTO EXECUTE_BACKUP
:POWER_ON
REM ### Powers on 7xNAS02
ECHO %LOGDATESTR% %LOGTIMESTR% 7xNAS02 is offline. Powering on now. >> %LOGFILE%
ECHO 7xNAS02 is offline. Powering on now.
ECHO.
SET previously_off=0
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\!SCRIPTS\7xNAS02-Power-On.ps1'" >> %LOGFILE%
ECHO %LOGDATESTR% %LOGTIMESTR% Pinging 7xNAS02 until it's available... >> %LOGFILE%
ECHO Pinging 7xNAS02 until it's available...
ECHO.
GOTO CHECK_IF_READY
:CHECK_IF_READY
REM ### Continually pings 7xNAS02 until it is online.
ping -n 1 %ipaddress1% | findstr TTL || GOTO CHECK_IF_READY
ping -n 1 %ipaddress1% | findstr TTL && GOTO EXECUTE_BACKUP
:EXECUTE_BACKUP
REM ### Executes GoodSync backup job, "STORAGE."
ECHO %LOGDATESTR% %LOGTIMESTR% Executing "STORAGE" backup job. >> %LOGFILE%
ECHO Executing "STORAGE" backup job.
ECHO.
C:\"Program Files"\"Siber Systems"\Goodsync\gsync sync "STORAGE" >> %LOGFILE%
IF %previously_off% == 0 (
ECHO.
ECHO %LOGDATESTR% %LOGTIMESTR% Sync job done. Shutting down 7xNAS02... >> %LOGFILE%
ECHO Sync job done. Shutting down 7xNAS02...
shutdown /m \\7xNAS02 /s /f /d p:0:0 /c "Executed by 7xNAS02-GSync-Script on 7xNAS01."
GOTO SHUTDOWNCHECK
)
IF %previously_off% == 1 (
ECHO.
ECHO %LOGDATESTR% %LOGTIMESTR% Sync job done. 7xNAS02 will stay powered on. >> %LOGFILE%
ECHO Sync job done. 7xNAS02 will stay powered on.
ECHO.
)
GOTO END
:SHUTDOWNCHECK
ping -n 5 %ipaddress1% >nul
IF ERRORLEVEL 1 (
REM ### 7xNAS02 has powered off.
ECHO.
ECHO %LOGDATESTR% %LOGTIMESTR% 7xNAS02 has powered off. >> %LOGFILE%
ECHO 7xNAS02 has powered off.
GOTO END
)
REM ### 7xNAS02 is still on. Looping to check IF the server has shut down.
ECHO ...
GOTO SHUTDOWNCHECK
:END
REM pause
ECHO %LOGDATESTR% %LOGTIMESTR% END OF SCRIPT >> %LOGFILE%
exit
EDIT: Thanks to #Mofi, the updated and working script is below.
#ECHO off
REM Change CMD window color and size.
color 37
mode 180,50
REM ### Set variables
SET IPADDRESS1=11.11.11.20
SET IPADDRESS2=10.0.3.1
CALL :GETDATETIME
SET LOGFILE=C:\!SCRIPTS\logs\7xNAS02-GSync-%NAMEDATESTR%_%NAMETIMESTR%.txt
:START
REM ### Checks IF 7xNAS02 is online. IF not, power it on.
ECHO ################################################################################################################################ >> %LOGFILE%
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% EXECUTING GSYNC SCRIPT >> %LOGFILE%
ECHO ################################################################################################################################ >> %LOGFILE%
ECHO/
ECHO This is an automated script to backup the storage array on 7xNAS01 onto 7xNAS02.
ECHO IF 7xNAS02 isn't powered on, the script will boot 7xNAS02, wait for it to come online,
ECHO and then execute the "STORAGE" backup job in GoodSync.
ECHO/
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% Checking power status of 7xNAS02... >> %LOGFILE%
ECHO Checking power status of 7xNAS02...
ECHO/
ping -n 1 %ipaddress1% | findstr TTL && GOTO ALREADY_ON
ping -n 1 %ipaddress1% | findstr TTL || GOTO POWER_ON
:ALREADY_ON
REM Sets variable to dictate that the server was already on before executing the script.
ECHO/
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% 7xNAS02 is already powered on and available. >> %LOGFILE%
ECHO 7xNAS02 is already powered on and available.
ECHO/
SET previously_off=1
GOTO EXECUTE_BACKUP
:POWER_ON
REM ### Powers on 7xNAS02
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% 7xNAS02 is offline. Powering on now. >> %LOGFILE%
ECHO 7xNAS02 is offline. Powering on now.
ECHO/
SET previously_off=0
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\!SCRIPTS\7xNAS02-Power-On.ps1'" >> %LOGFILE%
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% Pinging 7xNAS02 until it's available... >> %LOGFILE%
ECHO Pinging 7xNAS02 until it's available...
ECHO/
GOTO CHECK_IF_READY
:CHECK_IF_READY
REM ### Continually pings 7xNAS02 until it is online.
ping -n 1 %ipaddress1% | findstr TTL || GOTO CHECK_IF_READY
ping -n 1 %ipaddress1% | findstr TTL && GOTO EXECUTE_BACKUP
:EXECUTE_BACKUP
REM ### Executes GoodSync backup job, "STORAGE."
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% Executing "STORAGE" backup job. >> %LOGFILE%
ECHO Executing "STORAGE" backup job.
ECHO/
C:\"Program Files"\"Siber Systems"\Goodsync\gsync sync "STORAGE" >> %LOGFILE%
IF %previously_off% == 0 (
ECHO/
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% Sync job done. Shutting down 7xNAS02... >> %LOGFILE%
ECHO Sync job done. Shutting down 7xNAS02...
shutdown /m \\7xNAS02 /s /f /d p:0:0 /c "Executed by 7xNAS02-GSync-Script on 7xNAS01."
GOTO SHUTDOWNCHECK
)
IF %previously_off% == 1 (
ECHO/
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% Sync job done. 7xNAS02 will stay powered on. >> %LOGFILE%
ECHO Sync job done. 7xNAS02 will stay powered on.
ECHO/
)
GOTO END
:SHUTDOWNCHECK
ping -n 5 %ipaddress1% >nul
IF ERRORLEVEL 1 (
REM ### 7xNAS02 has powered off.
ECHO/
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% 7xNAS02 has powered off. >> %LOGFILE%
ECHO 7xNAS02 has powered off.
GOTO END
)
REM ### 7xNAS02 is still on. Looping to check IF the server has shut down.
ECHO ...
GOTO SHUTDOWNCHECK
:END
REM pause
CALL :GETDATETIME
ECHO %LOGDATESTR% %LOGTIMESTR% END OF SCRIPT >> %LOGFILE%
exit
:GETDATETIME
SET "HH=%time:~-11,2%"
SET "MM=%time:~-8,2%"
SET "SS=%time:~-5,2%"
SET "NAMETIMESTR=%HH: =0%%MM%"
SET "LOGTIMESTR=%HH: =0%:%MM%:%SS%"
SET "MYDATE=%DATE:~4,10%"
SET "NAMEDATESTR=%MYDATE:~6,4%%MYDATE:~0,2%%MYDATE:~3,2%"
SET "LOGDATESTR=%MYDATE:~6,4%/%MYDATE:~0,2%/%MYDATE:~3,2%"
GOTO :EOF
A simple solution for using region dependent but faster accessed DATE and TIME environment variables is the usage of a subroutine.
Append to end of your batch file after last command exit the lines:
:GetDateTime
SET "HH=%time:~-11,2%"
SET "MM=%time:~-8,2%"
SET "SS=%time:~-5,2%"
SET "NAMETIMESTR=%HH: =0%%MM%"
SET "LOGTIMESTR=%HH: =0%:%MM%:%SS%"
SET "MYDATE=%DATE:~4,10%"
SET "NAMEDATESTR=%MYDATE:~6,4%%MYDATE:~0,2%%MYDATE:~3,2%"
SET "LOGDATESTR=%MYDATE:~6,4%/%MYDATE:~0,2%/%MYDATE:~3,2%"
GOTO :EOF
This is the subroutine GetDateTime. And delete the lines at top of your batch file which also set those environment variables.
Above each line using either LOGDATESTR or LOGTIMESTR insert the line:
CALL :GetDateTime
Run in a command prompt window call /? for more information about this method to embed a batch file within a batch file and call it as subroutine.
One more hint: It is recommended to use echo/ instead of echo., see DosTips forum topic: ECHO. FAILS to give text or blank line - Instead use ECHO/

powershell $lastexitcode does not work when running batch files

I try to get the exitcode/errorlevel code from a bat file into the powershell script calling the bat file.
Althought the %ErrorLevel% is 1:
BAT file
call aCONFIGURATION
for %%f in (.\createData\*.g.sql) do sqlcmd -b -U %UserName% -P %Password% -S %sqlClonedServer% -d %sqlClonedDatabaseName% -i %%f -r1 1> NUL
echo %ERRORLEVEL%
When I do in the powershellscript
$lastexitcode its ALWAYS 0 but the %ErrorLevel% says 1
$build = "c:\my.bat"
$state = & $build
Write-Host $LASTEXITCODE
I am pulling my hairs of this crap powershell full with bugs.
I have read these links but they did not help as the result is different:
http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/06/get-legacy-exit-codes-in-powershell.aspx
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/05e37b8d-761b-4fd7-881e-977f114ad8d7/obtaining-errorlevel-return-codes-in-powershell-is-it-possible
How can I fix the $lastexitcode
echo %ERRORLEVEL% just writes the error code to stdout, after which the batch file exits normally.
If you want the batch script to actually return an error on exit, use exit /b [exitcode]:
call aCONFIGURATION
for %%f in (.\createData\*.g.sql) do sqlcmd -b -U %UserName% -P %Password% -S %sqlClonedServer% -d %sqlClonedDatabaseName% -i %%f -r1 1> NUL
exit /b %ERRORLEVEL%

%%G from For Loop changing from index to %G using

I am trying to write a batch file to automate some routine Matlab processes. The batch file loops through from 0 to a set value (usually between 50 and 75) using the For /L structure. The script copies the main Matlab script to the subfolder and runs it. The batch would normally continue onward so I put a :loop to wait until the Matlab ends.
echo off
setlocal EnableDelayedExpansion
REM The format is matlab_auto.in (max value).
For /L %%G in (0,1,%1) do (
REM Sanity check
echo 1 %%G
REM Create Outputs folder if non-existent
if not exist Outputs md Outputs
REM Copy .m file into deg folder and cd to folder
copy values_calc.m %%Gsort\values_calc.m
cd %%Gsort
echo Got to folder
REM Running .m script and sanity check
echo 2 %%G
matlab -nosplash -nodesktop -noFigureWindows -logfile output.log -r "run('values_calc.m');"
echo 3 %%G
REM Waiting for matlab to finish
:loop
tasklist /fi "imagename eq MATLAB.exe" |find ":" > nul
echo 4 %%G
if errorlevel 1 goto loop
echo Finished Matlab
echo 5 %%G
REM Copy .m outputs into outputs folder, ignoring confirmation
copy Output_*.* ..\Outputs /Y
echo Copied outputs
REM Sanity check and return home
echo 6 %%G
cd %~dp0
echo Home again
)
The problem I'm having is that when it ends after the first iteration of the For loop. Echo 1, 2, 3 are 0. Echo 4 shows 0 the first time through :loop but then it shows %G for the remainder of the loops and at Echos 5 and 6. It also does not continue into further iterations of the For loop. I'm assuming this is because %%G is no longer a number (or in the range specified).
I have tried implementing a call subroutine to use the goto outside the loop but then it opens the Matlab dozens of times, crashing the computer.
Any insight or advice is appreciated. Thank you.
EDIT: Changed the :: for commenting to REM. It did not resolve this issue but looks better.
EDIT 2: I have a test case that demonstrates the problem. Its something with the :loop or goto.
echo off
setlocal EnableDelayedExpansion
for /l %%G in (0,1,5) do (
:loop
echo %%G
pause
if %%G==0 goto loop
)
Yes. The execution of a GOTO command cancel any active (pending) FOR or IF commands that may be nested inside parentheses at any level. This way, the commands placed below the :loop label are executed inside the FOR context the first time, but after the goto command they are executed as if they were placed outside the FOR loop! The way to solve this problem is extracting the code below the label into a subroutine and then call :loop in the FOR.
echo off
setlocal EnableDelayedExpansion
REM The format is matlab_auto.in (max value).
For /L %%G in (0,1,%1) do (
REM Sanity check
echo 1 %%G
REM Create Outputs folder if non-existent
if not exist Outputs md Outputs
REM Copy .m file into deg folder and cd to folder
copy values_calc.m %%Gsort\values_calc.m
cd %%Gsort
echo Got to folder
REM Running .m script and sanity check
echo 2 %%G
matlab -nosplash -nodesktop -noFigureWindows -logfile output.log -r "run('values_calc.m');"
echo 3 %%G
REM Waiting for matlab to finish
call :loop
echo Finished Matlab
echo 5 %%G
REM Copy .m outputs into outputs folder, ignoring confirmation
copy Output_*.* ..\Outputs /Y
echo Copied outputs
REM Sanity check and return home
echo 6 %%G
cd %~dp0
echo Home again
)
goto :EOF
:loop
tasklist /fi "imagename eq MATLAB.exe" |find ":" > nul
REM echo 4 %%G
if errorlevel 1 goto loop
exit /B

Remote service checking batch file not quite working

Here is my pseudo:
Read from LIST
Ping to check if machine is awake | Report result
Check to see if SERVICE is running | Report result
NO? Is it stopped?
YES? Run it | Report result
NO? Must not be installed, remote install please! | Report result
This is driving me bonkers here... I can make the parts of this code work alone just fine, but when I combine it into a nested IF structure, it returns 'Network Error' and 'Running' if a machine does not have the service running...then a manual check at that machine shows it is still actually stopped. Same for machines without the service installed at all.Please tell me where I'm messing up.. Thanks!
#echo off
echo.
echo.
cls
set SERVICE=MyServ
for /f %%i in (\\127.0.0.1\c$\list.txt) do call :DOIT %%i
:DOIT
echo Checking %SERVICE% on %1
#ECHO off
ping -n 2 -w 1000 %1 >trial.txt
find "Reply from" trial.txt>nul
if %ERRORLEVEL% == 1 (echo %1 Network Unresponsive>> "\\127.0.0.1\c$\list_report.txt")
if %ERRORLEVEL% == 0 (
sc \\%1 query %SERVICE% | FIND "STATE" | FIND "RUNNING"
if %ERRORLEVEL% == 0 (echo %1 Running>> "\\127.0.0.1\c$\list_report.txt")
if not %ERRORLEVEL% == 0 (
sc \\%1 query %SERVICE% | FIND "STATE" | FIND "STOPPED"
if %ERRORLEVEL% == 0 (
sc \\%1 start %SERVICE%
echo %1 forced start>> "\\127.0.0.1\c$\list_report.txt""
)
if not %ERRORLEVEL% == 0 (
xcopy /f /y "\\127.0.0.1\!\theAPP.exe" "\\%1\c$\temp\"
\\127.0.0.1\!\psexec \\%1 -s -n 10 -d cmd /c "c:\temp\theAPP.exe"
echo %1 Installed>> "\\127.0.0.1\c$\list_report.txt""
)
)
)
this should fix the issue
for /f %%i in (\\127.0.0.1\c$\list.txt) do call :DOIT %%i
:DOIT
if not "%1"=="" (
echo Checking %SERVICE% on %1
echo.
ping -n 2 -w 1000 %1 | find "Reply from" >nul
if ERRORLEVEL 1 echo %1 Network Unresponsive>> \\127.0.0.1\c$\list_report.txt else (
sc \\%1 query %SERVICE% | find "RUNNING" > nul
if ERRORLEVEL 1 (
sc \\%1 start %SERVICE% > nul
echo %1 Forced Start>> \\127.0.0.1\c$\list_report.txt
) else (
echo %1 Running>> \\127.0.0.1\c$\list_report.txt)
xcopy /f /y \\127.0.0.1\c$\text.txt \\%1\c$\temp\ > nul
\\127.0.0.1\c$\psexec \\%1 -s -n 10 -d cmd /c "type c:\temp\text.txt"
echo %1 Installed>> "\\127.0.0.1\c$\list_report.txt")
)
)
part of the issue is that you have to test for if not %1="" at the top of the script. that is where you get the erroneous text..
then you had some nesting issues, so i used ELSE instead.
you will have to change the text.txt to your filename.exe (and omit the "type" command)
please check answer if this solves your problem
fyi, you will need to have administrator access on the remote machine so that you can turn on and off services

How to make a OR statement in a batch file?

Hi want to exclude 2 or more files from my batch file.
My batch file executes all SQL files in that folder.
Here is the code:
ECHO %USERNAME% started the batch process at %TIME% >output.txt
FOR %%G IN (*.sql) DO (
//IF would go here to skip unwanted files
sqlcmd.exe -S RMSDEV7 -E -d ChaseDataMedia7 -i "%%G" >>output.txt
)
pause
So, how would i add and if statemant to skip the files in the loop that i don't want to execute?
You can chain IFs;
FOR %%G IN (*.sql) DO (
if not %%G==foo.sql if not %%G==bar.sql (
some command "%%G"
)
)
#echo off
setlocal EnableDelayedExpansion
set unwantedFiles=foo bar baz
for %%g in (*.sql) do (
set "test=!unwantedFiles:%%~Ng=!"
if "!test!" == "!unwantedFiles!" (
echo %%~Ng.sql is not unwanted, process it:
echo Process with %%g
)
)
Take a name and copy unwantedFiles by removing current name. If the result is the same as before, this name is NOT in unwantedFiles, so process it...