I want to execute a PowerShell script from Command Prompt. I have verified script from PowerShell, it worked fine. I went to script location and executed it as
./hyperv_disk_ops.ps1 -op 'getDiskAttachmentInfo' -vmid '{6612D0CB-BCC3-44D4-988B-526500578D54}' -disk_ids ("Microsoft:7B036CE0-5D67-46BA-AF7B-B2AFD8DD7946\83F8638B-8DCA-4152-9EDA-2CA8B33039B4\0\0\D")
But when I tried running it from command prompt as
powershell.exe C:\hyperv_disk_ops.ps1 -op 'getDiskAttachmentInfo' -vmid '{6612D0CB-BCC3-44D4-988B-526500578D54}' -disk_ids ("Microsoft:7B036CE0-5D67-46BA-AF7B-B2AFD8DD7946\83F8638B-8DCA-4152-9EDA-2CA8B33039B4\0\0\D")
it gave me an error
ERROR: Failed to find object of [Microsoft:7B036CE0-5D67-46BA-AF7BB2AFD8DD794683F8638B-8DCA-4152-9EDA-2CA8B33039B400D] disk which is associated with [{6612D0CB-BCC3-44D4-988B-526500578D54}] VM.
Both are exact same but why it is not running from Command Prompt?
Try running from the command prompt with double backslashes, like so:
powershell.exe C:\hyperv_disk_ops.ps1 -op 'getDiskAttachmentInfo' -vmid '{6612D0CB-BCC3-44D4-988B-526500578D54}' -disk_ids ("Microsoft:7B036CE0-5D67-46BA-AF7B-B2AFD8DD7946\\83F8638B-8DCA-4152-9EDA-2CA8B33039B4\\0\\0\\D")
It looks like, in the error you provided, all of the slashes are being omitted in the disk path.
Related
Writing a script to retrieve various environment parameters back from a list of servers. My script returns no value when ran but the same command returns the desired value outside of a script.
I have tried using a couple of variations to retrieve the same data. One of the commands fails because of restrictions placed on the accounts I have access to. The second command works but only if executed in an elevated mode.
This fails with access denied (pwdx is restricted)
dzdo pgrep -f /some/path | xargs pwdx
This works outside of a script but returns no value within a script
dzdo /bin/readlink -e /proc/"$(pgrep -f /some/path)"/cwd
When using "bash -x" to execute my scriipt, I see the "readlink" code is blank.
Ideally, I would like to return the PID and path of the process running as the "pgrep" command does. I can work with the path alone as returned by the "readlink" version returns. The end goal is to gather the information from several servers for audit purposes. (version, etc.)
Am I using the wrong syntax for the "readlink" command? I'm fairly new to coding bash scripts so I appreciate any guidance to help understand when to to what if I'm using a command in a script vs command line.
If pwdx is the restricted program, you need to run that with dzdo, not pgrep.
pgrep -f /some/path | dzdo xargs pwdx
I am trying to monitor the cmd output of a certain executable .exe and use it for another process running at the same time.
The problem is that all cmd redirecting functions ( '>','>>','<' and '|') would only redirect the output after a successful return of the last command.
What I wanted to do is to generate some kind of streaming log of my cmd.
You can run in your process in background by using
start /b something.exe > somefile.txt
Windows 20H2: Redirection works fine when logged in as true administrator but will NOT work when logged in as a created administrative user. I have used it for years to redirect the output of a multi target backup system using Hobo copy to put the console output in a log file. I have never been able to get it to work successfully in Windows 10 ver 19 or 20 on a created administrative user.
You can prefix the command with "cmd /c" to start a new command prompt, and redirect the output of the command prompt:
cmd /c YOUR CODE > TextFileName.txt
Note : Use ONLY single greater than (>)
Since the output of cmd is going to TextFileName.txt.
Whereas this misses the error output, so you are not able to see : Request to UnKnown timed-out for each failed address.
I am trying to run following command
ssh xxx#99.99.99.99 ". ./.profile; myscript 2&1 >> /tmp/2244455.log"
But it comes up with following error
sh: 1: execute permission denied
When i run myscript 2&1 >> /tmp/2244455.log on my remote server it works perfectly.
Also when i run ssh xxx#99.99.99.99 ". ./.profile; myscript it works perfectly.
Please can yo help me with this issue
myscript is not owned by xxx, permissions are
ls -ltrh myscript
-rwxr-xr-x 1 yyy other 11K May 18 15:04 myscript
The 2&1 syntax is wrong; if you want to redirect stderr to stdout, you need to:
2>&1
You also have quotes that are not nested properly; the backtick `` is overlapped with the double quotes. EDIT: I see you've edited the question, but there's now an unpaired backtick at the beginning of your command
So, I'm guessing what you're after with the quotes, but your whole command might be:
ssh xxx#99.99.99.99 ". ./.profile; myscript 2>&1 >> /tmp/2244455.log"
This would create /tmp/2244455.log on the remote 99.99.99.99 machine.
Putting backpacks around the ssh command will cause your local shell to attempt to run its output as a new command line. Get rid of those, if that's not just a typo from formatting your question.
The real problem is that you're missing the > on the redirect. 2>&1, not 2&1. The >less version just adds 2 as an argument to the command and then attempts to run that command in the background while running a command named 1 in the foreground.
i wants to know how to configure the executestream command for the below command.
copy C:\input\ip.txt \\host2\C:\destFolder\ip.txt
Actually if i open cmd prompt(AnyPath) then write this command it could worked in windows.
But i need to process those command in NiFi.
I tried those command in following attributes like below.
Command Arguments:copy C:\input\ip.txt \\host2\C:\destFolder\ip.txt
Command Path:C:\Windows\system32\cmd.exe
Argument Delimiter: space
Here after success of executestream command processed in OutputStream relationship but functionality of the command not issued.
In that command i have copy the file(ip.txt) from host1 into host2 machine.Generally if i run that command in cmd.exe then file copied into host2.
But if configure those parameters in ExecuteStreamcommand i have received outputstream but my command not run and file not moved into host2.
Can anyone guide me to resolve this?
you are trying to call a command without any streaming of the flow file.
so you need ExecuteProcess processor
Example with dir command:
Command : cmd
Arguments : /C dir c:\11
Delimiter : [space]
/C for cmd means call and exit
Command Arguments:copy C:\input\ip.txt \\host2\C:\destFolder\ip.txt
Add to front [/C]
Command Arguments:**/C** copy C:\input\ip.txt \\host2\C:\destFolder\ip.txt
Having issues getting this shell script to run in windows task scheduler.
#!/bin/bash
# Script to ping the VPN server for testing
RESULT=$(ping 192.168.1.252 | grep "Lost" | awk {' print $10 '})
LOG=/home/admin/results.txt
if [ "$RESULT" -gt 0 ];then
echo "VPN 192.168.1.252 NOT pinging" >> $LOG
else
echo "VPN Online"
fi
When I run it in cygwin, it runs with no issue, but when I attempt to run it from command prompt, I get the following:
C:\cygwin64\bin>bash test.sh
test.sh: line 4: grep: command not found
test.sh: line 4: awk: command not found
test.sh: line 7: [: : integer expression expected
My question is, how do I get it to run with bash instead so that it actually knows the grep and awk commands?
In Windows Scheduler, I have Action: Start A Program
Details: C:\cygwin64\bin\bash.exe
Argument: test.sh
Start in: C:\cygwin64\bin
Am I missing something?
I figured it out.
In the Windows Task Scheduler, I had to pass:
Program/script: C:\cygwin64\bin\bash.exe
Add arguments: -c -l test.sh
Start in: C:\cygwin64\bin
In correction to what Jimmy found:
Add arguments: -c -l "c:/FileFolder/test.sh"
You don't need the Start in argument anymore.
For the longest time I was experiencing the same issue as the OP: command not found errors when trying to run a shell script from Task Scheduler or the Command Prompt, despite the fact that running the same script from a Cygwin terminal worked fine.
After some more research I eventually realised that the reason was because my usual Bash PATH ~/.bashprofile wasn't being loaded, and that I needed to use Windows' Environment Variables window to add C:\cygin64\bin to my PATH environment variable (system or user, it doesn't really matter). This directory contains common system executables like grep and awk, which is why Bash is unable to locate them until the path is added to Windows' PATH.