As part of a powershell script im working on, i use rsh in order to connect to another shell however after using this all subsequent commands are ignored and the script just ends.
My workflow is:
rsh "podname"
cd "path"
exit
Everything after I use rsh is ignored. Is there a way to get the script to wait until the rsh is completed?
Using: oc rsh foo "cd /path && somecommand" resulted in an error saying that no such directory existed. Is this because it's trying to find /path on the local machine and not the remote one?
When you just run oc rsh, that is an interactive command that might interfere with your script. So when running a command inside a container, you should add the commands as an argument to the oc rsh command, here is an example:
# Run the command 'cat /etc/resolv.conf' inside pod 'foo'
oc rsh foo cat /etc/resolv.conf
So in your case something like the following could help in your case:
oc rsh foo "cd /path && somecommand"
Related
I need to expand variables before running the SCP command as a result I can't use single quote. If I run the script using double quotes in Powershell ISE it works fine.
But doesn't work if I run the script through command prompt.
I'm using zabbix to run the script which calls the script as [cmd /C "powershell -NoProfile -ExecutionPolicy Bypass -File .\myscript.ps1"]
Here is the code that needs to run SCP using Cygwin bash.
if ((test-path "$zipFile"))
{
C:\cygwin\bin\bash.exe -l "set -x; scp /cygdrive/e/logs/$foldername/dir1/$foldername.zip root#10.10.10.10:~/"
}
Output:
/usr/bin/bash: set -x; /cygdrive/e/logs/myfolder/dir1/server.zip root#10.10.10.10:~/: No such file or directory
If I run the same command above in Cygwin manually it works.
I even tried to use bash -l -c but then the SSH session is stuck maybe because the root#10.10.10.10 becomes $1 according to the documentation.
Documentation link
-c If the -c option is present, then commands are read from
the first non-option argument command_string. If there are
arguments after the command_string, the first argument is
assigned to $0 and any remaining arguments are assigned to
the positional parameters. The assignment to $0 sets the
name of the shell, which is used in warning and error
messages.
Figured it out. It was halting when using bash -c was due to StrictHostKeyChecking, the known hosts thing (where you get a prompt to type yes/no). I set the -v switch to SCP and it showed me the Debug logs where it was halting.
Had to set scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null options.
The complete line now looks like the following:
c:\$cygwin_folder\bin\bash.exe -c ("/usr/bin/scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -v -i /cygdrive/c/cygwin/home/myuser/.ssh/id_rsa /cygdrive/e/logs/$foldername/dir1/$foldername.zip root#10.10.10.10:~/")
On RHEL, the below command works:
psql -h hostname -U username -p port_no -d database -f /tmp/myfile.sql &> logfile01.txt
On FreeBSD, this throws error:
"Invalid null command"
Please suggest.
If you use this only on the command line then there is no need to change the shell.
To redirect stdout and stderr to a file in C-Shell synthax simply use ">& filename".
Different story is, if you want to write shell scripts. Bourne Shell and it's clones (like i.e. Bash) are better suited for writing script. See this Unix FAQ "Csh Programming Considered Harmful": http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
This redirection works in bash
&> logfile01.txt
, but it does not work in csh which is the default shell in FreeBSD.
# set | grep shell
shell /bin/csh
# ls -la &> logfile01.txt
Invalid null command.
Bash is not installed by default. You can install it
pkg install bash
and configure it as the default shell.
ss.exe command -I- won't run using local service
If I run the below command as a network user it works.
"C:\Program Files\SourceSafe\win32\SS.EXE" GET $/JavaSource -R -W -GL "d:\Release\com\fitltd" -GF- -O- -I- Set d:\Release\com\fitltd as the default folder for project $/JavaSource?(Y/N)N
However if this command is called using a local service user (Jenkins service) the command stops waiting for input (you can't see the question it is waiting (see above) for unless you run the same thing using a network user).
so the output looks like: "C:\Program Files\SourceSafe\win32\SS.EXE" GET $/JavaSource -R -W -GL "d:\Release\com\fitltd" -GF- -O- -I-
I am running Windows 2008 R2.
My perl code does this
#!/usr/bin/perl
sleep 2;
exec 'ssh', '-o', "ConnectTimeout=10", "newhost", "sleep 3;pwd";
the problem is when sleep is executing what ever I type on the terminal (during execution)
disappears to non interactive shell in newhost.
eg:
user#a02$perl test.pl
ls
user#a02$ #ls is not executed
command ls executes if I don't use exec or system.
Is there a way to execute the contents of the buffer?
After a bit of digging i found ssh has has an stdio redirector when used with -n option.
http://www.pixelbeat.org/programming/stdio_buffering/
To tell ssh that the remote command doesn't require any input use the -n option
Check everywhere for a reason but nothing I found matches my specific problem. I have a program in C:\somefoldername\anothersubdirectory\andanother\ of the remote pc that I try to run using PSEXEC but it does not take. PSEXEC just does not want to run anything for me. Now if I run a ping or tasklist via psexec, it works, though obviously this is in PATH.
So I am putting in:
PSEXEC \\pcname C:\somefoldername\anothersubdirectory\andanother\program.exe
and nothing happens.
I even wrote a batch script that I tried running in two different ways.
Script is just:
#ECHO OFF
C:\somefoldername\anothersubdirectory\andanother\program.exe
EXIT
and I had it copied to the remote pc's main directory (maybe I need to put it in a folder) and then I tried running C:\batch.bat using:
PSEXEC \\pcname C:\batch.bat
I also tries running:
PSEXEC \\pcname -c \\servername\batch.bat
so it copies it over to PATH.
Neither worked.
Does any program I try to run via PSEXEC have to be in the remote pc's path?
I do have to admit that I have not done running an EXE remotely, but I have written lengthier scripts using psexec that use batch file on a server without any hiccups.
What is weird to is that the program I run has parameters and I task that runs through it, so I first taskkill it remotely, then I PSEXEC the SAME EXACT EXE as:
psexec \\pcname C:\...\program.exe -a -few -parameters ODBC
and that works. When I try to open just program.exe on its own, nope doesn't take.
I also did try psexecing iexplore.exe and that didn't work either.
So gotta use the -i option. In addition to that, gotta use -p + -u or -s to load system hardware dependent gui. This is why large portions of the gui was missing, or I assume why.
Can you please try this format
psexec \\machineName -u username -p password /accepteula -h cmd /c
C://somefoldername//anothersubdirectory//andanother//program.exe >>log.txt
More Clearly
Download the PSEXEC tool zip file in your user machine and unzip it.
Open command prompt and go to the psexec path.
In my machine it is: D:\PsTools
Run following command line
Syntax:
D:\PsTools> psexec \\ip_address -u username -p Password cmd /c executablename arguments >> test.log