How to find the script that writes in the log - servicenow

I need help finding a script that writes to the log with "information" level. only appears in the "source" field of the log the option " *** script "
Any ideas?

Related

Check if a script has run atleast once before

Is there a way to see if any PowerShell script has executed at-least once before, without the script itself creating any logs? I.e. is there some sort of a native record keeping mechanism for already executed scripts (an example would be an event generating and hence creating an event log), meaning a log of the script actually executed was made at runtime but externally?
For example : If script A was executed once today, check during the second execution (say 2 days later) of script A if it had already executed before.
Can this be done through any Event logs, or through environment variables?
EDIT: Please note, for this particular script, no text files or logs can be made. Is there a way to do this without actually leaving a trace "physically" but instead relying on any parameters being set when a script executes?
EDIT2: This script would be executing with the least of privileges, so not only an account which does not have admin permissions, but would also not have approved permissions to create text or log files.
How about self-modifying code? It's technically cheating, as the change is being done in the script file itself. No external logging is done, though.
write-host -nonewline "Script has started"
$src = get-content $MyInvocation.MyCommand
$header = $src[0]
if($header -notmatch "^#") {
write-host " ...first time!"
$newScript = #()
$newScript += "#"
$newScript += $src
set-content $MyInvocation.MyCommand $newScript
} else { write-host " ...nth time!" }
The script reads its own contents. If the first line doesn't start with a hash, it's the first invokation. The script then creates a new set of source code. The first line is a hash, original source comes after that. Then the original script is overwritten.
As a side note, the requirement to log-but-not-log is self-contradictory just as #Mathias R. Jessen pointed out. There is, however, process tracking audit available in Windows. Also, there is script block logging. In theory (and with proper permissions), one might search the Windows' event logs for previous run attempts.
I'd much rather pop the why stack and find out the underlying reason, as the requirement to eat and keep a cacke sounds very much like an XY problem.

Permission Denied When Building in Sublime Text 3

I am attempting to utilize Lua on Windows 10 with Sublime Text 3. When I attempt to build and run a script I receive the following error:
lua: cannot open C:\Program Files (x86)\Lua\5.1: Permission denied
I have added full permissions to the folder.
I am only attempting to run a simple print statement:
print("hello")
The expected result is hello output in the results window.
The build system that ships with Sublime for executing Lua programs looks like this:
{
"cmd": ["lua", "$file"],
"file_regex": "^(?:lua:)?[\t ](...*?):([0-9]*):?([0-9]*)",
"selector": "source.lua"
}
The important aspect here is that the command to be executed is lua with a first argument that is the name of the current file. From the error message you're seeing, Lua looks like it's trying to execute a directory instead of the name of a program. Or if you will, if this was a directory permission problem I would expect it to tell you the name of the file that it can't access, not the folder than the file is stored in.
It's also suspicious that the name of the folder is the install location for lua itself, and that the error message seems to indicate that it's lua itself generating the error.
Based on all of this, my guess would be that you didn't save your Lua script before you executed the command. That would cause $file to expand out to an empty string, making the first argument empty. Since the build is using cmd, internally windows is being told specifically to run a program named lua with an empty string as it's first argument.
It looks like the interpreter first tries to put the current working directory onto the filename and then execute it, and since the file name is empty, it ends up trying to execute a directory, which is where the permission problem comes from.
Once you save the file the first time and it has a name, Sublime will automatically re-save it every time you run the build as long as Tools > Save all on build is checked; that option won't prompt you to save brand new files that don't have names yet, though.

Powershell start transcript error

I am running a powershell script from a batch file:
try {
Start-Transcript -path ("C:\PS\Logs\XXXX_Session_QA_" + (Get-Date).tostring("yyyyMMdd-hhmmss-tt") + ".txt")
<Rest of the Code>
}
catch {
stop-transcript
}
Every time I run the script, I see the error
Error: Transcription has not been started. Use the start-transcript command to start transcription.
I have gone through some or most of the previous posts and the code should work but it isn't triggering at all. The initial log file isn't being created either. Any idea why this could be happening or any help here?
Does the folder structure exist for where you are trying to write the transcript to? According to the documentation, it is required (see italics below):
-Path
Specifies a location for the transcript file. Enter a path to a .txt
file. Wildcards are not permitted. If you do not specify a path,
Start-Transcript uses the path in the value of the $Transcript global
variable. If you have not created this variable, Start-Transcript
stores the transcripts in the $Home\My Documents directory as
\PowerShell_transcript..txt files.
If any of the directories in the path do not exist, the command fails.
https://technet.microsoft.com/library/05b8f72c-ae3b-45d5-95e0-86aa1ca1908a(v=wps.630).aspx
You will also need permission to write to that path of course.
So... if the Start-Transcript cmdlet is throwing an error, you are then catching it in the catch{} block (invisibly) which then executes the Stop-Transcript.
This presumably is what is actually causing the error message: the net result is that you are trying to stop transcription when it never started in the first place.

Execute command with windows command line and capture output in rolling file

I have a command line program that produces output that I would like to log to a file.
I know that I can redirect the output of a command (foo.exe for example) to a file using the > operator, but for this current project I need more than just simple output functionality. I would also mention that I can't change any of the code in foo.exe.
I am looking for a command line utility/command that can do the following:
Log the output of a foo.exe to a file
Place a timestamp on each individual output of foo.exe
When the current log file reaches a certain specified size (say 1mb), close the current file and start putting log data in a new file.
In a perfect world the utility would encapsulate the command I wish to execute and log its output, looking something like the following:
log.exe -MaxLogSize=1mb -FileName="FooOutput.log" -Execute="foo.exe"
Any help or suggestions are appreciated!

Findstr on remoteserver unsuccessful

I am trying to run this .bat script
set target_path =\\remoteserver\c$\newfolder\newfolder1\logs >log.txt
findstr /m "ERROR" "%target_path%\file1.txt" >> log.txt
The expected output from this .bat file is that it will pick up "ERROR" string from file1.txt from the "remoteserver" and will show as output in log.txt.
But,once when i run this script it shows me the following error
FINDSTR: Cannot open \remoteserver\c$\newfolder ...
Kindly, suggest me the flaws or correct script so that the above script gets executed successfully with the expected output .
thanks for your quick update and sorry for acknowledging late. I tried executing the batch script with the necessary corrections you mentioned needed in the script , but still i face the same problem . I am unable to fetch the "ERROR" from log file and get the expected output. Is there any other field to be added to "FINDSTR" to pull up the ERROR ??.. Kindly, assist me for the same.
Thanx in advance.
Not at all sure how you achieved that response given the scant 2 lines of code you've posted.
You are setting the variable "target_path ", not "target_path" according to your first line. Batch is sensitive to spaces in a set statement.
Since "target_path" is not set, it's a total mystery how your response is Cannot open \remoteserver\c$\newfolder ... unless the variable "target_path" had been previously set in the environment. The findstr should, with the posted code, have been executed against the file "\file1.txt" - not as reported.

Resources