Three task batch files for my game servers - list

I need 3 different batch files for 3 different tasks:
-log the output of HldsUpdateTool.exe console, so far I don't see what's going on but I managed this:
#echo off
echo Updating...
call :Logit>>log.txt 2>&1
exit /b 0
:Logit
hldsupdatetool.exe -command update -game "Counter-Strike Source" -dir "Source 2007 Dedicated Server" -verify_all -retry
start notepad log.txt
-clean this log to get a files and folders list; the log will look like this:
Checking bootstrapper version ...
Updating Installation
Determining which depot(s) to install/update...
5 depot(s) will be installed/updated
0:30 Checking local files and building download list for depot 242 'Counter-Strike Source Shared' version 126
0:30 Connecting content server session for version 126
0:31 [80.239.194.146:27030] Connecting...
0:31 [80.239.194.146:27030] Connection established; handshaking...
0:31 [80.239.194.146:27030] Sending login message...
0:31 Fetching version 126 manifest
0:41 Reading version 126 checksum table
0:54 Calculating download size and verifying checksums
0:54 Checking...: /
0:54 Checking...: cstrike
0:54 Checking...: cstrike\bin
0:54 Checking...: cstrike\cfg
0:54 Checking...: cstrike\classes
0:54 Checking...: cstrike\maps
0:54 Checking...: cstrike\maps\graphs
0:54 Checking...: cstrike\maps\soundcache
0:57 Checking...: cstrike\materials
0:57 Checking...: cstrike\materials\brick
0:57 Checking...: cstrike\materials\buildings
0:57 Checking...: cstrike\materials\carpet
0:57 Checking...: cstrike\materials\composite
0:57 Checking...: cstrike\materials\concrete
0:58 Checking...: cstrike\materials\console
etc... later on files do not have extensions!
-clean the server folder from any files or folders not listed!
I did search around for 2 days but this is as far as I can go by myself...

You can shorten that to
#echo off
hldsupdatetool.exe -command update -game "Counter-Strike Source" -dir "Source 2007 Dedicated Server" -verify_all -retry >Log.txt
start notepad Log.txt
The problem with the files not showing extensions will be down to the program you are running, all the batch does is call the exe and redirect the output.

First of all,I'm a definitely newer to batch :)
As for the 2nd question:
-clean this log to get a files and folders list; the log will look like this:
for /f "tokens=3" %G in ('findstr /i /c:"checking..." log.txt')do echo %G>>_.log
May it works for you.
Update:
I download your log.txt and test immediately,this is the result(file names _.log):
/
cstrike
cstrike\bin
cstrike\cfg
cstrike\classes
cstrike\maps
cstrike\maps\graphs
cstrike\maps\soundcache
cstrike\materials
cstrike\materials\brick
cstrike\materials\buildings
cstrike\materials\carpet
cstrike\materials\composite
cstrike\materials\concrete
cstrike\materials\console
cstrike\materials\cs_assault
cstrike\materials\cs_havana
cstrike\materials\cs_italy
cstrike\materials\cstrike
cstrike\materials\de_aztec
cstrike\materials\de_cbble
cstrike\materials\de_chateau
cstrike\materials\de_dust
cstrike\materials\de_nuke
cstrike\materials\de_piranesi
cstrike\materials\de_prodigy
cstrike\materials\de_tides
cstrike\materials\de_train
cstrike\materials\decals
cstrike\materials\decals\concrete
cstrike\materials\decals\metal
cstrike\materials\decals\wood
...
Maybe i misunderstood your meaning?
Update again
As for 3rd question
#echo off
set /p origin=Where is the original folder?(Type absoulute path directly.)
echo origin: %origin%
set /p destin=Where can i put file temporarily(Type absoulute path directly.)
echo destination :%destin%
for /f %%G in (_.log) do (
if "%%G"=="/" (
echo.
) else (
xcopy %origin%\%%G %destin%\%%G /H /K /R /E /D /I /Y
))
rm -rf %origin%
set /p origin=What is the name of original folder?(Type name)
rename %destin% %origin%
May it help you!
Update the third time :)
Because the first edition maybe little confusing for you.Sorry for my lacking of ability ti code well.
#echo off
setlocal enabledelayedexpansion
set MAXNUM=100
set /p origin=Where is the original folder?(Type absoulute path directly.)
echo origin: %origin%
set backup_origin=%origin%
for /L %%H in (1,1,%MAXNUM%) do (
for /F "delims=\" %%G in ("!origin!") do (
set name=%%G
set origin=!origin:%%G\=!
))
set father=!backup_origin:\%name%=!
xcopy !father!\!name! !father!\backup_!name! /H /K /R /E /D /I /Y
::copy files
rm -rf !father!\!name!
::delete origin
rename !father!\backup_!name! !name!
::rename the new folder using the old's name
if your files are in such an format C:\template\example\cstrike\materials\brick,you should just type c:\template\example,which includes \hl2 \cstrike and so on.
I work on Win7,which you may not.So I recommend you to adjust my batch file to your OS.Before running ,check that you have xcopy,rm,rename working for you.T

Related

Find and remove remote hidden file

I'm trying to create a small script that looks for a specific file in an hidden folder and remove it using IF ELSE, but it doesn't seem to work. It works when I try to find and delete a local file, but not when I try a remote hidden file.
This is my code:
#echo off
set /p destination="Enter destination PC name: "
#echo off
set /p username="username: "
echo.
echo [33m'Removing 'notes.ini' file[0m
timeout /T 2 /NOBREAK > nul
echo.
if exist "\\%destination%\C$\Users\%username%\AppData\Local\Lotus\Data\notes.ini" (
del /A /Q /F "\\%destination%\C$\Users\%username%\AppData\Local\Lotus\Data\notes.ini"
echo [92m'Notes.ini' cleared.[0m
) else (
echo [33m'Notes.ini' doesn't exist.[0m
)
echo.
timeout /T 2 /NOBREAK > nul
echo [92mScript clompleted[0m
I tried with a local file, and then the scripts works, but not with a remote hidden file. I always get the "else" statement as return with hidden files

Changing mkv to mp4 with a batch script

What I want the .bat to do is to "scan" the files, in this case, .mkv, looking for streams (if there's more than a video stream and an audio stream you might need a matroska file). If you have an audio stream and a video stream, let's change the files as there's no reason to use matroska.
Currently I have 10 seasons of a TV show, which I personally ripped from my own DVDs, and they are in .mkv format. But inside the .mkv there's only video and audio, the subtitles are separate.
The only reason I want to change .mkv to .mp4 is that plex can't use .mkv.
The current code I have to remove metadata on all .XXX in the folder:
if not exist "%~dp1_temp" (
goto foldercreate
)
else (
goto continue
)
:foldercreate
echo.
echo Created temp folder.
echo -
mkdir _temp
attrib _temp +h
set errorlevel=
:continue
for %%f in (*%~x1) do (
title Fixing %%f...
move "%%f" _temp >nul
echo Currently fixing %%f...
ffmpeg -xerror -hide_banner -i "%~dp1_temp\%%f" -map_metadata -1 -codec copy -map 0 "%~dp1%%f" -loglevel warning -stats
if %errorlevel% neq 0 (
pause
)
del "%~dp1_temp\%%f"
echo -
)
if %errorlevel% neq 0 (
echo FFmpeg errored...
pause
)
echo All done! removing temp dir...
rmdir _temp /S /Q
timeout /t 2 /nobreak>nul
:eof

Is there a way to SFTP files from Linux directory to Windows within SAS Enterprise Guide?

I am trying to SFTP files from Linux to a Windows directory using SAS, but I keep running into errors.
My code is:
filename attn '/<Linux Directory>/file.doc';
filename outfile sftp '/<Linux Directory>/file.doc'; cd ='C:\Temp\file.doc'
options="oIdentityFile='~/.ssh/authorized_keys' -oPort=<port number>"
host="<hostname>" user="<username>" DEBUG ;
data _null_;
infile attn ;
file outfile ;
input;
put _infile_;
run;
But I keep facing the below errors:
ERROR: Physical file does not exist, /<Linux directory>/file.doc.
NOTE: usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config] [-o ssh_option] [-P sftp_server_path] [-R
num_requests] [-S program] [-s subsystem | sftp_server] host sftp [user#]host[:file ...] sftp
[user#]host[:dir[/]] sftp -b batchfile [user#]host
NOTE: cd C:\Temp\task1045v2_13yrs_cc.doc
ERROR: Directory or file C:/temp/file.doc/ doesn't exist.
NOTE: The SAS System stopped processing this step because of errors.
Basically I am trying to recreate the below Visual Basic code in SAS:
open sftp://<userid>:<password>#<hostname> -hostkey="ssh-rsa <Port Number> <key>"
option echo on
option batch on
option confirm off
option transfer ascii
lcd "<Windows path/>"
cd <Linux path>
get <file.doc> /*the file which need to get transferred from linux to windows*/
close
exit
VB Code (actual code to transfer):
strPath = "C:\Temp\"
strFileName = "<filename>.txt"
strFullName = objFSO.BuildPath(strPath, strFileName)
strLogName = objFSO.BuildPath(strPath, "<logfilename>.log")
Set objShell = CreateObject("WScript.Shell")
objShell.CurrentDirectory = strPath
Set objExec = objShell.Exec("""C:\Program Files (x86)\WinSCP\WinSCP.exe"" /console /script=""" & strFullName & """ /log=""" & strLogName & """")
Set objExec = Nothing
Set objShell = Nothing
Any advice would be appreciated. Thank you!
Looks like you are trying to move a file named file.doc without changing its name. Make sure to tell SFTP the proper locations on the target machine where you want to write the file.
%let source=/<Linux Directory>;
%let target=C:\Temp;
%let fname=file.doc;
filename attn "&source/&fname";
filename outfile sftp "&fname" cd ="&target\"
options="oIdentityFile='~/.ssh/authorized_keys' -oPort=<port number>"
host="<hostname>" user="<username>" DEBUG
;
Note: When a statement is so long that you want to break it into multiple lines for readability I find it best to put the semi-colon that ends the statement on a new line. Just like you would put the end; statement on a new line for a block of multiple statements. This will make it easier to spot missing (or as in your case, extra) semi-colons in the code.

remove string from filenames with .bat batch file

I have a folder with thousands of filenames like this. I need to put them inside folders and remove the useless parts from the filenames. I need to do this before adding the files inside my XBMC library.
[ www.AnnoyingSpam.com ] Some.File.Name.With.A.Very.Long.String.avi
[ www.AnnoyingSpam.com ] Another.File.With.A.Very.Long.String.mpg
[ www.AnnoyingSpam.com ] Again.And.Again.mp4
First, I want to strip the AnnoyingSpam.com tags in the files
Then, create a folder based on the file name without the tag and without the extension
Finally, move the file to the new folder
Repeat for the rest of the files in the root directory of the batch file
So far all I got is a script that will create folder and move files. But it adds the tag "Folder" to each folder and it doesn't remove the AnnoyingSpam.com tag
#echo off
for /f "usebackq delims=?" %%a in (`dir /a-d /b`) do (
if not "%%~dpnxa"=="%~dpnx0" call :func "%%~a"
)
goto :EOF
:func
set file=%~1
set dir=%file% Folder
md "%dir%" Folder 2>nul
move "%file%" "%dir%"
goto :EOF
So my question is how can i remove these strings from the folder names that are being created in the above script:
"[ www.AnnoyingSpam.com ]"
" Folder"
Since you are performing the check if not "%%~dpnxa"=="%~dpnx0" call :func "%%~a", my understanding is that you will be running the batch from inside the 'target' folder.
What follows is a batch script, based structurally on your sample, that accomplishes the necessary filtering and handles the rename and move operations.
#echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "usebackq delims=?" %%a in (`dir /a-d /b`) do (
if not "%%~dpnxa"=="%~dpnx0" call :func "%%~a"
)
endlocal
echo Done.
goto EOF
:func
set file=%~1
for /F "delims=" %%a in ("!file!") do (
rem stripped extension, next step is to filter to remove the 'spam' part
set "c=%%~Na"
rem original filename, will be needed for the renaming
set "o=%%~a"
rem store the extension to use later on when re-constructing the filename
set "e=%%~xa"
rem this is effectively a multichar stripper; filters the 'spam' part out
set "c=!c:[ www.AnnoyingSpam.com ] =!"
rem reconstruct the filename
set "f=!c!!e!"
rem echo !o! : !c! : !e! ::: !f!
rem rename original file to the filtered version
ren "!o!" "!f!"
rem create dir named after the filtered filename, if it does not already exist; just a precaution
if not exist !c! (md !c!)
rem move the filtered file to the appropriate dir
move "!f!" "!c!" > nul
)
:EOF
The script is almost self-explanatory (see the comments inside), however there are some aspects that I would like to point out:
The instructions setlocal ENABLEDELAYEDEXPANSION and endlocal, that in fact form a wrap around the for-loop, establish that the variables inside the loop will be evaluated (expanded) at the execution time and not during parse time. Notice that the variables are referenced inside the loop as !var!. See more on this here.
The removal of the unwanted 'spam' part is performed by this command: set "c=!c:[ www.AnnoyingSpam.com ] =!". What it does is best described by the following example: set "var=!var:substring1=substring2!", has as a result the substitution of every occurrence of substring1 by substring2 in var.
If substring2 is null (as is the case here), then the actual effect is the removal of every substring1 pattern found in the original variable. More on this here, and for an interesting use as a multichar delimiter see dbenham's answer here.
And, as always, test thoroughly before you use the script on the actual folders.
I know you've asked for a batch script, but if you have php installed, you can use this:
renameSpam.php
<?php
$removeTag = "[ www.AnnoyingSpam.com ]";
foreach(glob("*.*") as $file){
if (strpos($file, $removeTag) !== false) {
$newFile = trim(str_ireplace($removeTag, "", $file));
$ext = pathinfo($newFile, PATHINFO_EXTENSION);
$fnNoExt = basename($newFile,".".$ext);
if(!is_dir($fnNoExt)){
mkdir($fnNoExt, 0777);
rename($file, "./$fnNoExt/$newFile");
}else{
rename($file, "./$fnNoExt/$newFile");
}
}
}
Place renameSpam.php on the directory with the files to rename and execute as php renameSpam.php.
I've tested this on windows and linux and it works as intended.

how to programmatically restart WAMP or Apache?

As part of some automated deploy + test scripts I use to verify programming done for a site, I have some scripts which update Apache's config files. I would like to programmatically restart WAMP so the changes take effect. Is there a good way to do this?
The scripts are powershell.
This is whats in my apache bin folder:
iconv
ab.exe
abs.exe
ApacheMonitor.exe
apr_dbd_odbc-1.dll
apr_ldap-1.dll
dbmmanage.pl
htcacheclean.exe
htdbm.exe
htdigest.exe
htpasswd.exe
httpd.exe
httxt2dbm.exe
libapr-1.dll
libapriconv-1.dll
libaprutil-1.dll
libeay32.dll
libhttpd.dll
logresolve.exe
openssl.exe
php.ini
php5isapi.dll
php5ts.dll
rotatelogs.exe
ssleay32.dll
wintty.exe
zlib1.dll
You can use this command to restart Wamp, Apache, MySQL services:
To start services
NET START wampapache
NET START wampmysqld
To stop services
NET STOP wampapache
NET STOP wampmysqld
For mariaDB, replace wampmysqld with wampmariadb.
For 64 bits: append 64 to the service names.
Simple execute command:
httpd.exe -k restart
ps. this is my wathdog for windows
#echo off
:loop
timeout /t 30 /nobreak
REM .
tasklist /FI "IMAGENAME eq php-cgi.exe" 2>NUL | find /I /N "php-cgi.exe">NUL
if "%ERRORLEVEL%"=="1" goto Process_NotFound
tasklist /FI "IMAGENAME eq httpd.exe" 2>NUL | find /I /N "httpd.exe">NUL
if "%ERRORLEVEL%"=="1" goto Process_NotFound
goto loop
:Process_NotFound
TASKKILL /F /IM php-cgi.exe
TASKKILL /F /IM httpd.exe
ping 127.0.0.1 -n 2
Apache -k start
ping 127.0.0.1 -n 3
cls
php.exe -r "$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://server.name/'); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch);"
ping 127.0.0.1 -n 3
ab.exe -n 10 -c 3 http://server.name/
goto loop
CTRL+R -> Type (Command) -> Right Mouse -> Run Administrator
Go to your wamp aptech bin folder eg : D:\wamp\bin\apache\apache2.4.9\bin>
Type httpd.exe -d (Show All apache parameter command )
httpd.exe -k start -n wampapache64
httpd.exe -k stop -n wampapache64
httpd.exe -k restart -n wampapache64
Graphical Instruction :
Step First:
Step Second:
I ended up writing some code to find the "wampapache" service and restarting it.
public static void ResetApache()
{
ServiceUtil.RestartService("wampapache", 10000);
}
...
public class ServiceUtil
{
public static void RestartService(string serviceName, int msTimeout)
{
ServiceController service = new ServiceController(serviceName);
int startTicks = Environment.TickCount;
TimeSpan timeout = TimeSpan.FromMilliseconds(msTimeout);
if (service.Status != ServiceControllerStatus.Stopped
&& service.Status != ServiceControllerStatus.StopPending)
{
service.Stop();
}
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
int midTicks = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(msTimeout - (midTicks - startTicks));
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
//int finalTicks = Environment.TickCount;
//var totalTime = TimeSpan.FromTicks(finalTicks - startTicks);
//Console.WriteLine("Reseting process took " + (totalTime.TotalMilliseconds/1000.0) + " seconds.");
}
}