I am writing CICD in the YAML file of GitHub, therein one instance I need to compare the branch names where a pull request is being triggered to determine which environment the other underlying process thereafter should use to the do MsBuild and other tasks.
Below is the comparison in YAML:
- name: build
shell: cmd
run: |
if not x%GITHUB_REF_NAME:RSDEV_=%==x%GITHUB_REF_NAME% (
SET PLATFORM=Qa
) else if not x%GITHUB_REF_NAME:Feature_=%==x%GITHUB_REF_NAME% (
SET PLATFORM=Qa
) else if not x%GITHUB_REF_NAME:Release_=%==x%GITHUB_REF_NAME%(
SET PLATFORM=Uat
) else (
echo "Check something went wrong"
exit 1
)
However, when I ran pull-request, it says
The syntax of the command is incorrect
Am I following the correct way for branch comparison like release_** and so on cmd?
Btw, I was able to figure out the reason behind the error: The syntax of the command is incorrect
There was an indentation error in the else block:
- name: build
shell: cmd
run: |
if not x%GITHUB_REF_NAME:RSDEV_=%==x%GITHUB_REF_NAME% (
SET PLATFORM=Qa
) else if not x%GITHUB_REF_NAME:Feature_=%==x%GITHUB_REF_NAME% (
SET PLATFORM=Qa
) else if not x%GITHUB_REF_NAME:Release_=%==x%GITHUB_REF_NAME%(
SET PLATFORM=Uat
) else (
echo "Check something went wrong"
exit 1
)
[Courtesy Edit]
The correct syntax in cmd.exe:
if /i not "%GITHUB_REF_NAME:RSDEV_=%" == "%GITHUB_REF_NAME%" (
SET "PLATFORM=Qa"
) else if /i not "%GITHUB_REF_NAME:Feature_=%" == "%GITHUB_REF_NAME%" (
SET "PLATFORM=Qa"
) else if /i not "%GITHUB_REF_NAME:Release_=%" == "%GITHUB_REF_NAME%" (
SET "PLATFORM=Uat"
) else (
echo Check something went wrong
exit 1
)
Related
I am trying to copy attributes for *.mkv *.mp4 video files. I have found a way to copy file attributes, but it is quite slow as it is calling Powershell to use it commands.
powershell ^(ls '!orig-file!'^).CreationTime = ^(ls '%%I'^).CreationTime
powershell ^(ls '!orig-file!'^).LastWriteTime = ^(ls '%%I'^).LastWriteTime
powershell ^(ls '!orig-file!'^).LastAccessTime = ^(ls '%%I'^).LastAccessTime
...................
%%I equals new-file for each FOR loop iteration
Is there a way to do this faster without Powershell?
Otherwise, I assume it would be possible to only call Powershell once and copy all 3 or more attributes in 1 line? I'am assuming that reading each file attribute individually is the only way to copy, but I would prefer all attributes if there are any more to copy.
EDIT: FULL CODE: (with all remarked/commented lines removed) ( Batch Convert Videos audio from one format to another )
#ECHO OFF
SETlocal
SET drive="~dp0"
SET string=%CD%
SETlocal EnableExtensions EnableDelayedExpansion
SET "drive=G:"
SET ^"Exclude-AlltheseFolders=#snapshot,output^"
SET "Convert_Audio1=Y"
SET "Convert_TO=aac"
SET "Codec1=eac3"
SET "Codec2=flac"
SET "Codec3=dts" &SET "Codec4=pcm_s24le" &SET "Codec5=aac" &SET "Codec6=ac3"
SET "KeepExtraAudio_NoOrig=Y"
SET "KeepOrigAudio=N"
SET "OverWriteFiles=N"
SET "ExtractTime=Y"
SET "time_to_start_from=00:00:10" &SET "duration_to_capture=00:00:15"
SET "TempFilePath=C:\Windows\Temp\ffmpeg-CountingScript-AllFilesInCurrentDirlist%DT%--%HH%.%MM%.%SS%.txt"
IF !ExtractTime! == Y ( SET "FFmpgextractTime= -ss !time_to_start_from! -t !duration_to_capture!")
ECHO THIS IS JMK1
IF !OverWriteFiles! == Y (SET "OverWrite=-y ") ELSE (SET "OverWrite=-n ")
IF !Convert_Audio1! == Y (
IF !Convert_TO! == aac ( set "Convert_TO=libfdk_aac" )
SET "FFmpgConvertStream1=-c:a:0 !Convert_TO! -b:a:0 640k -disposition:a:0 default"
IF !KeepExtraAudio_NoOrig! == Y (
SET "FFmpgXtraStream=-c:a copy"
)
IF !KeepOrigAudio! == Y (
SET "KeepOrigAudio_ffMpg=-map 0:a:0? -c:a:0 copy"
SET "KeepExtraAudio_NoOrig=Y"
)
) ELSE (
SET "ConvertCodecs=1"
SET "KeepOrigAudio_ffMpg=-c:a:0 copy"
SET "KeepExtraAudio_NoOrig=Y"
)
SET "delm1=^\^>" /c:"^\^<"
SET ^"Exclude-Final=/c:"\^<!Exclude-AlltheseFolders!\^>"^"
SET ^"Exclude-Final=!Exclude-Final:,=%delm1%!^"
dir *.mkv *.mp4 /A-D-H /B /S |findstr /R %Exclude-Final% /v /i>%TempFilePath%
Echo: These are the folders being Excluded: "!Exclude-AlltheseFolders!"
SET "FINALCOMMAND="
SETlocal EnableExtensions DisableDelayedExpansion
SET "ProgramFolder=C:\Program Files\FFmpeg-v2020\bin"
SET "ProbeOptions=-v quiet -select_streams a:0 -show_entries "stream^^=codec_name" -of json"
SET "FilesFound=0" & SET "FilesEncoded=0" & SET "output="
for /F "delims=" %%I in (%TempFilePath%) do (
SET "output=%drive%%%~pI%%~nxI" & SET folder=%drive%%%~pI & SET "filename=%%~nxI" & SET /A FilesFound+=1
SETlocal EnableExtensions EnableDelayedExpansion
IF exist "%drive%%%~pIoutput\%%~nxI" (SET "Convert_Audio1=N") ELSE SET "Convert_Audio1=Y"
IF "!Convert_Audio1!" == "Y" (
SET "AudioCodec=" & SET "ConvertCodecs="
for /F "eol={ tokens=1,2 delims=,:[ ]{} " %%B in ('""%ProgramFolder%\ffprobe.exe" %ProbeOptions% "%%I""') do (
IF "%%~B" == "codec_name" (
IF not defined AudioCodec (
SET "AudioCodec=%%~C"
)
IF "%%~C" == "%Codec1%" (SET "ConvertCodecs=1"
) else IF "%%~C" == "%Codec2%" (SET "ConvertCodecs=1" & ECHO Codec is: %%~C
) else IF "%%~C" == "%Codec3%" (SET "ConvertCodecs=1" & ECHO Codec is: %%~C
) else IF "%%~C" == "%Codec4%" (SET "ConvertCodecs=1" & ECHO Codec is: %%~C
) else IF "%%~C" == "%Codec5%" (SET "ConvertCodecs=1" & ECHO Codec is: %%~C
) else IF "%%~C" == "%Codec6%" (SET "ConvertCodecs=1" & ECHO Codec is: %%~C
)
)
)
)
IF !ConvertCodecs! == 1 (
ECHO [91m==!TIME!================[0m!Codec1! [94min[0m- %%I [91m=========[0m
)
IF !ConvertCodecs! == 1 (
IF /I "!output!" == "%%I" (
SET "output=%~dp0output\!filename!"
MKDIR "%~dp0output\"
) ELSE (
MKDIR "%drive%%%~pI"
)
SET "FINALCOMMAND=ffmpeg !OverWrite!-hide_banner%FFmpgextractTime% -loglevel quiet -hwaccel auto -stats -i "%%I" -map 0:v -map_metadata 0 -movflags use_metadata_tags -map 0:a? -map 0:s:0? -c:s:0 copy -c:v copy %FFmpgXtraStream% %FFmpgConvertStream1% %KeepOrigAudio_ffMpg% "!output!" "
ECHO this is the command1: !FINALCOMMAND!
!FINALCOMMAND!
ECHO [91m=====[0mCOMPLETE[91m===============[0m .
IF not %FilesEncoded% == 0 ECHO This one was a failure. Count Encoded so far: "%FilesEncoded%"
IF not errorlevel 1 SET /A FilesEncoded+=1
powershell ^(ls '!output!'^).CreationTime = ^(ls '%%I'^).CreationTime
powershell ^(ls '!output!'^).LastWriteTime = ^(ls '%%I'^).LastWriteTime
powershell ^(ls '!output!'^).LastAccessTime = ^(ls '%%I'^).LastAccessTime
for /F "delims=" %%p in ("!ConvertCodecs!") do (
ECHO THIS IS P: %%p
ENDLOCAL
SET /A FilesEncoded=%%p+FilesEncoded
)
) ELSE ( ECHO ##NOT PROCESSING##: !TIME! - %%I ## & ECHO [91m=====--[0mFILE ALREADY EXISTS! [91m======================[0m Next File [91m===========================[0m )
)
)
IF %FilesFound% == 1 ( SET "PluralS=" ) else SET "PluralS=s"
ECHO [91m***************************************************************************************[0m
ECHO Re-encoded %FilesEncoded% of %FilesFound% video file%PluralS%.
ECHO [91m***************************************************************************************[0m
endlocal
endlocal
endlocal
exit /b
The following copies the specified attributes using a single
powershell.exe call:
Note the use of gi, a built-in alias of the Get-Item cmdlet.
ls - on Windows - is (unfortunately) a built-in alias of the Get-ChildItem cmdlet (whose use would work here too, and whose PowerShell-idiomatic alias is gci); however, such aliases - named for other shells' / platforms' built-in commands / utilities are best avoided - see the bottom section of this answer for more information.
Enclosing the entire (implied) -Command argument in "..." obviates the need for ^-escaping of individual chars.
powershell "$target = gi '!orig-file!'; $source = gi '%%i'; 'CreationTime', 'LastWriteTime', 'LastAccessTime' | foreach { $target.$_ = $source.$_ }"
Note that the above could still fail in the following cases:
If a file name happens to contain ' itself; if so, use \""...\"" (sic) instead of '...'
See this answer for more information.
If a file name happens to contain [ and ]; if so, use gi -LiteralPath instead of just gi, which implies gi -Path.
I am trying to write a batch file that will:
connect to FTP server using WinSCP
use RSA keys to authenticate
try two different keys, in case one fails
send an email notification about fail transfers
save logs
Solution to the question:
#echo off
:: FTP Configuration
SET TRIES=2
SET INTERVAL=10
SET Server=user#server.com
SET HostKey=
SET ProdHostKey=ssh-rsa 2048 KeyKeyKeyKeyKeyKeyKeyKey
SET DRHostKey=ssh-ed25519 256 KeyKeyKeyKeyKeyKeyKeyKey
SET PrivateKey=C:\RSA_Privatekey\Key.ppk
SET Source=/Files/Work/
SET Destination=D:\Inbox\
:: Log File Configuration
SET DateStamp=%date:~-4,4%%date:~-10,2%%date:~-7,2%
SET LogFile=D:\Logs\WinSCP\WinSCP-FTP_%DateStamp%.log
:: Email Configuration
SET SMTPServer=smtp.server.com
SET EmailFrom=%computername%#server.com
SET EmailTo="email1#server.com", "email2#server.com"
SET EmailSubject="FTP Transfer Failure"
SET EmailAttachment="%LogFile%"
SET EmailBody="FTP transfer failed.`r`nLog file attached."
:Begin
SET HostKey=%ProdHostKey%
:Retry
:: Launch WinSCP
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="%LogFile%" /ini=nul ^
/command ^
"Option confirm off" ^
"open sftp://%Server%/ -hostkey=""%HostKey%"" -privatekey=""%PrivateKey%"" -rawsettings ConsiderDST=0" ^
"Get -delete "%Source%*.*" "%Destination%"" ^
"Close" ^
"Exit"
SET WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
SET /A TRIES=%TRIES%-1
IF %TRIES% GTR 1 (
echo Transfer failed, retrying using DR hostkey, in %INTERVAL% seconds...
timeout /t %INTERVAL%
SET HostKey=%DRHostKey%
goto Retry
) else (
echo Connection failed, aborting and sending an email notification.
echo.
echo From: %EmailFrom%
echo To: %EmailTo%
echo Subject: %EmailSubject%
echo Attachments: %EmailAttachment%
echo Message: %EmailBody%
powershell.exe -NoLogo -NoProfile -Command ^
"Send-MailMessage" ^
"-To %EmailTo%" ^
"-From '%EmailFrom%'" ^
"-Subject '%EmailSubject%'" ^
"-SmtpServer '%SMTPServer%'" ^
"-Body "%EmailBody%"" ^
"-Attachments %EmailAttachment%"
exit /b 1
)
)
exit /b %WINSCP_RESULT%
I have a script setup to run overnight on my Filemaker server, but every night it returns this error:
Schedule "Recheck All Flags" scripting error (201) at "MasterDatabase : Recheck All Flags : ### : Set Field
Where ### is just a random number, probably the line in the script. In the above example let's just say it was 398.
I can't copy and paste the script to here, but it is very simple. It's one big loop over all records in the database and it checks a bunch of If statements. It looks like:
If [MasterDatabase::Start date = ""]
Set Field [MasterDatabase::Flagged for Discrepancy; "Yes"]
Commit Records/Requests [With dialog:Off]
End If
Why might this be failing when running on the server overnight?
Make sure you tell the server to go to the correct layout before the script starts, when the server starts up the script it will do the work on the layout that it is configured for the DB to open by default.
You can do something like:
If [ $$PLATFORM = "Server" ]
(Go to Layout X)
End If
The global variable $$PLATFORM can be defined in your On First Window Open Script like so:
Case (
PatternCount ( Get ( ApplicationVersion ) ; "Server" ) ;
"Server" ;
PatternCount ( Get ( ApplicationVersion ) ; "Data API" ) ;
"Data API" ;
Get ( SystemPlatform ) = 4 ;
"Web" ;
Choose (
Get ( Device ) ;
"Desktop" ; // 0 - Unknown
"Desktop" ; // 1 - Mac
"Desktop" ; // 2 - PC
"Tablet" ; // 3 - Tablet
"Phone" // 4 - Phone
)
)
If you already have that covered then make sure whatever user you are using for the PSOS has access to that layout, records scripts and fields.
I have batch file in which i am restarting a machine and want to check if machine is back online then execute the code block else after particular time inform the user the machine is not online
I want to check something like:
pingresult = ping \\machinename
if (pingresult == true)
{
execute some task
}
else
{
keep pinging for say 5min. if after 5mins machine is not up show message to user
}
This will try pinging %machinename% for 100 times with a default timeout of 3 seconds: 3s * 100 = 300s, i.e. 5 minutes.
for /L %%N IN (1, 1, 100) DO (
ping -n 1 %machinename%
if not ERRORLEVEL 1 (
set pingresult=true
goto done
)
)
set pingresult=false
:done
if %pingresult% == true (
echo "ping ok, doing something..."
) else (
echo "no reply after 5 mins, error!"
)
I am quite an expert when it comes to programming in the MSL language, however I am unfamiliar with raw commands and whatnot.
I am in development of a new script. In this script I would like to check if $4 in what a user says is a registered nick or not but I do not know how to do this.
Thank you very much for any help and/or advice in advanced.
Best Regards,
Tim
Update:
raw 307:*:{ set $+(%,%chan,-,%CheckNick) Registered }
on *:TEXT:*:#:{
if ($1 == !regtest) {
set %chan $remove($chan,$chr(35))
set %CheckNick $4
whois $4
}
if ($($+(%,%chan,-,%CheckNick),$4),5) != $null) {
do this...
}
else {
else message...
}
}
I got this to work to check however my if statement to check if the variable has been set or not is being ignored...
Edit:
I tried using this:
checkNickReg $chan $2 $nick
...And echoing this:
echo -a Target: $1
echo -a Nick: $2
echo -a Status: $3
echo -a Chan: $3 - $chan
I'm trying to get a response to the channel such as; $nick $+ , $1 is not registered/registered/registered but not logged in.
What I've posted above is obviously wrong as it doesn't work, however I've tried a few methods and I'm actually not sure how the data is passed on with out the likes of tokenizing or setting variables...
Reply
[01:59:06] <~MrTIMarshall> !isReged mr-dynomite
[01:59:08] <&TornHQ> : mr-dynomite status is: NOTLOGGED
EDIT: mr-dynomite is not currently on, should this not = does not exist or does this check even when their not on, if so this is bloody brillant!!!
[02:00:04] <~MrTIMarshall> !isReged MrTIMarshall
[02:00:04] <&TornHQ> : MrTIMarshall status is: LOGGEDIN
$4 does not seem to work and what is the difference between 'exists, not logged in' and 'recognized, not logged in'?
Also, how does the data get passed on without setting variables or tokenizing?
(P.S. Thank you so much for the help you have dedicated so far!)
Another Edit:
I've been taking an in depth look today, am I correct in thinking if 0 or 1 the user is either not on-line or not registered (in the comments it says 0 = does not exists / not online, 1 = not logged in whereas 2 also says not logged in but recognized of which I'm unsure as what recognized means. Otherwise I'm very grateful for this script help and whatnot I'm just unclear on the numbers...
Since you have not specified any particular network I wrote an outline for some common networks around (that actually have user authentication systems). You should be able to add many other networks following the pattern.
Basically you execute /checkNickReg <target> <nick> [optional extra data] and when the server replays with the registration info (if applicable) use the on isReged signal event to handle the reply. Everything else is pretty much transparent.
EDIT: Looks like the specified network you are using (Torn) uses the standard anope services. So I updated the code to support that network.
; triggers when you get nick registration info back
; $1 = Target
; $2 = Nick
; $3 = Status, can be: LOGGEDIN, RECOGNIZED, NOTLOGGED
; $4- = Everything else passed
on *:signal:isReged:{
echo -a Target: $1
echo -a Nick: $2
echo -a Status: $3
echo -a Else: $4-
}
; reg lookup routines
alias checkNickReg {
set %reg. $+ $network 1
set %reg.target. $+ $network $1
set %reg.nick. $+ $network $2
set %reg.other. $+ $network $3-
; Freenode uses: NickServ ACC <nick>
if ($network == Freenode) msg NickServ ACC $2
; Rizon/SwiftIRC/OFTC/Torn use: NickServ STATUS <nick>
elseif ($istok(Rizon SwiftIRC OFTC Torn, $network, 32)) msg NickServ STATUS $2
}
; listen for replays
on *:notice:*:*:{
if ($($+(%, reg., $network),2)) {
;
var %target = $($+(%, reg.target., $network),2)
var %nick = $($+(%, reg.nick., $network),2)
var %other = $($+(%, reg.other., $network),2)
;
unset %reg*. $+ $network
if (($network == FreeNode) && ($2 == ACC)) $&
|| (($istok(Rizon SwiftIRC OFTC Torn, $network, 32)) && ($1 == STATUS)) {
; FreeNode:
; 0 = does not exist
; 1 = exists, not logged in
; 2 = recognized, not logged in
; 3 = logged in
; Rizon/SwiftIRC/OFTC/Torn:
; 0 = does not exists / not online
; 1 = not logged in
; 2 = recognized, not logged in
; 3 = logged in
if ($3 < 2) var %status = NOTLOGGED
elseif ($3 == 2) var %status = RECOGNIZED
else var %status = LOGGEDIN
}
;send status signal
.signal isReged %target %nick %status %other
}
}
(Extra Note: It might be useful to add an extra check to make sure $nick is AuthServ/NickServ for security reasons.)
A simple usage example is:
; Just a basic example of how to call it.
on *:text:!isReged &:#:{
checkNickReg $chan $2 $nick
}
on *:signal:isReged:{
msg $1 $4: $2 status is: $3
}
Type !isReged <nick>
Edit: The data gets passed to the on isReged event via global variables. I set them in the checkNickReg alias and I clean them up in the on notice event. So you never see them because they get cleaned up. They are passed to the isReged signal event in $1-.
On most IRCDs, it's only exposed in the WHOIS response for a user, if at all. Running a WHOIS every time a user says something is inadvisable, especially because server admins may receive a notification every time it happens.