installing programs on remote machines - windows

I want to run an installer on remote computer remotely. This mean I first need to copy it somehwere on that remote machine and then run it using tools like psexec. I am using following command to run the program but is there anyway within psexec to copy the file first and then run it. I will appreciate any suggestions about it?
psexec \\RemoteComputer -u username -p something -i c:\PAthOnRemoteMachineMachine\SomeInstaller.msi

You could try PAExec. It supports the same syntax, but also has additional features like "upload-and-run"
paexec \\RemoteComputer -u username -p something -i -c -csrc c:\MyLocalDir\SomeInstaller.msi

The path after -csrc is the path of the source file from where paexec would copy the file from, on the source machine. To direct paexec to execute the file off a specific location on the remote machine we'd have additionally specify the "remote launch path" like c:\windows\abc.exe , optionally with arguments (x y and z below) i.e. copy abc.exe from c:\MyLocalDir on the source machine to c:\windows on the remote machine and launch it there (C:\windows on the remote) with x y and z arguments. The "Reached end of command before seeing expected parts" error is because the last part (remote launch specification) is missing.
paexec \\RemoteComputer -u username -p something -i -c -csrc c:\MyLocalDir\abc.exe c:\windows\abc.exe x y z

Related

FTP using Unix shell script and then triggering a task

I have a requirement at hand in Unix where I need to build a shell script.
The requirement is below:
I need to SFTP a file (let's say CSV file) from my dev server to uat server.
After the SFTP is done to that server, as soon as the file comes there and the exit code of the previous SFTP is 0, I need to trigger a task (this task I can take care of).
I have the basic idea on SFTP but I am not aware of how to trigger the next task as soon as the file comes to the uat server.
Please need a pseudo code to start my exploration.
If you want to copy from somewhere to your local machine and run a command locally
If you have access to ssh then it can be done easily which I am doing it usually.
For example I have a backup file from one of my server. We can get a copy this way using scp
scp root#server:/home/weekly.sql.zip .
. means put the file with its name here on this directory I am in now
the problem with this command is that it has an interaction for getting password so to eliminate this we can install sshpass and use it this way:
sshpass -p'your-password' scp root#server:/home/weekly.sql.zip .
Since we are using bash and it take care of exiting code if you add and && operator then you can add a second command so to be triggered after first command has successfully done.
sshpass -p'your-password' scp root#server:/home/weekly.sql.zip . && unzip weekly.sql.zip
First task is copying a file and second is to unzip it.
installing sshpass:
sudo apt install -y sshpass
If you want to copy from your local machine to somewhere and run a command remotely
sshpass -p'your-password' scp test.txt root#address:/home/ && sshpass -p'your-password' ssh root#address cat /home/test.txt
Which does this:
copy file test.txt to the server
then read it by cat command

PsExec and WindDirStat on a remote system - how to run

I'd like to be able to run WinDirStat on a remote machine that I have administrative rights over but it does not work.
This is what I have done:
Run CMD as admin:
psexe.exe -i -s cmd.exe
From the new prompt:
psexec.exe \\host -u username winddirstate.exe
I type in my PW and it does not launch
Both running Windows 7 Enterprise.
Usage: psexec [\\computer[,computer2[,...] | #file]][-u user [-p psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,...] cmd [arguments]
-a Separate processors on which the application can run with
commas where 1 is the lowest numbered CPU. For example,
to run the application on CPU 2 and CPU 4, enter:
"-a 2,4"
-c Copy the specified program to the remote system for
execution. If you omit this option the application
must be in the system path on the remote system.
-d Don't wait for process to terminate (non-interactive).
-e Does not load the specified account's profile.
-f Copy the specified program even if the file already
exists on the remote system.
-i Run the program so that it interacts with the desktop of the
specified session on the remote system. If no session is
specified the process runs in the console session.
-h If the target system is Vista or higher, has the process
run with the account's elevated token, if available.
-l Run process as limited user (strips the Administrators group
and allows only privileges assigned to the Users group).
On Windows Vista the process runs with Low Integrity.
-n Specifies timeout in seconds connecting to remote computers.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
-r Specifies the name of the remote service to create or interact.
with.
-s Run the remote process in the System account.
-u Specifies optional user name for login to remote
computer.
-v Copy the specified file only if it has a higher version number
or is newer on than the one on the remote system.
-w Set the working directory of the process (relative to
remote computer).
-x Display the UI on the Winlogon secure desktop (local system
only).
-arm Specifies the remote computer is of ARM architecture.
-priority Specifies -low, -belownormal, -abovenormal, -high or
-realtime to run the process at a different priority. Use
-background to run at low memory and I/O priority on Vista.
computer Direct PsExec to run the application on the remote
computer or computers specified. If you omit the computer
name PsExec runs the application on the local system,
and if you specify a wildcard (\\*), PsExec runs the
command on all computers in the current domain.
#file PsExec will execute the command on each of the computers listed
in the file.
cmd Name of application to execute.
arguments Arguments to pass (note that file paths must be
absolute paths on the target system).
-accepteula This flag suppresses the display of the license dialog.
-nobanner Do not display the startup banner and copyright message.
First you are in Same Directory of Psexec or set path of PSexec in Environment path then put this command
psexec.exe \host -u username -p password -s cmd /C C:\full_remote_path_of_\windirstat.exe
OR
put one bat file inside your remote machine like C:\abc\run.bat and put this code inside it
echo off
C:\full_path_of_\windirstat.exe
echo "Success"
and run command from your local
below command will run that bat file present on remote
psexec.exe \host -u username -p password -s cmd /C "C:\remote\run.bat"
OR
there is no need to put run.bat file in remote machine put only on local and then give below command
psexec.exe \host -u username -p password -s -i -c -f "C:\local\run.bat"
OR
psexec.exe \host -u username -p password -s -i -c -v "C:\local\run.bat"
-s ----->as a Administrator
-i ----->Interactive
-c ----->copy run.bat to remote
-f -----> if run.bat already exist on remote Computer
-v -----> if higher version on local and lower version on remote then it
will copy otherwise not
USING FILE NAME
If you want to run on many remote machine and all remote machine username and password are same so put one file like host.txt and put all ip's line by line there is no space on starting on line then give below command and it will run serially
PsExec.exe #C:\full_path\host.txt -c -s -u username -p password run.bat
**Parallel Running in All Remote Machines **
if you want to run parallel then give one more parameter -d then it will not wait to finish process until it finished and you can use for loop and put PSexec command inside it
Save Result in some file THREE Variation
**First Variation**
Below will copy the iname.bat file in remote system and execute it and save the result in success.txt inside local machine directory in which we are running PSexec
PsExec.exe \remote_ip -u username -p password -c -f "iname.bat">success.txt
**Second Variation**
below will run test.bat present on remote machine and make Success.txt on localmachine
PsExec.exe \remote_ip -u username -p passowrd cmd /C "C:\abhi\test.bat">success.txt
**Third Variation**
this will run test.bat present on remote machine and make Success.txt on remote machine
PsExec.exe \remote_ip -u username -p password -i cmd /C "C:\abhi\test.bat > C:\abhi\success.txt"

Can't launch putty with remote command?

I'm attempting to launch putty via the command line in such a way that it runs a command on the server (I want to create a windows shortcut, to tail a log file)
So far I have a batch file containing this
"C:\Program Files (x86)\PuTTY\putty.exe" -ssh -t -pw -m tail_catalina_out -load "myprofile"
And within my server I have a file at the root directory named tail_catalina_out with the following contents.
tail -f /opt/tomcat/logs/catalina.out
Putty launches and my session starts successfully, but no command appears to be carried out despite this? Am I misunderstanding how this works?
You don't need -ssh with -load profile (and if you use a nonstandard port like my test it doesn't work at all); in fact you don't need it with [user#]host because it's the default
-pw -m tail_catalina_out uses -m as your password (which I hope is incorrect, so you should be reprompted unless publickey auth is set-up) and ignores tail_catalina_out
the file for -m must be local i.e. on the PuTTY machine not on the server (although the commands in it will be sent to, and must be valid on, the server)
Thus: "\path\to\putty" -t -m localcmdfile -load profile
You could also use plink which runs in the console and takes either -m localfile or the actual remote command on the command line after the last option (like the OpenSSH client ssh):
"\path\to\plink" -t -load profile tail -f remotefile
As usual, you can omit the quotes around the path if it contains no space. Personally I use \progra~2 instead of bothering with "\program files (x86)" but that's just me, and it may depend on a clean install (instead of upgrade).

PsExec is not copying file over to execute

I want to run a script I called "systemInfo.vbs" that outputs to a logfile the system name and service pack.
In command prompt I am doing "PsExec.exe \REMOTECOMPUTER -c systemInfo.vbs".
I am running this from a directory on my local system that has ONLY PsExec.exe and systemInfo.vbs
I get the error
PsExec could not start systemInfo.vbs on REMOTESERVER: "The system
cannot find the file specified.
Any idea why this may be? I thought I could do this to run a remote script as if it is on the remote server?
You need to give the path to your script either on the remote pc or through a UNC path on a share on your pc or a netsworkdrive. So if the script has a copy on the remote c:\
PsExec.exe \\REMOTECOMPUTER -c c:\systemInfo.vbs
or if it is on the share \\mypc\shared
PsExec.exe \\REMOTECOMPUTER -c \\mypc\shared\systemInfo.vbs
Also you need to make sure you have administrator rights on the pc where you start the script and depending on what your script does possibly on the remote pc as well.
For anyone who might encounter this in the future, the -c flag does allow you to copy over a file for execution; the documentation didn't specify, but you need to follow it with the path on your local machine to the binary you want copied and executed. (I have submitted a pull request to the documentation.)
For example, this could be used to add the "Blend for Visual Studio SDK for .NET" to a remote installation of Visual Studio 2017 Professional by copying the web installer (named vs_professional.exe) to that machine (\\TargetMachine) with credentials, (note the DOMAIN is only if you're using a domain instead of local user), and executing it with appropriate parameters.
D:\PSTools\PsExec64.exe "\\TargetMachine" -u "DOMAIN\user" -p "pass" -h -c "D:\deploy\vs_professional.exe" vs_professional.exe modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional" --add Microsoft.Component.Blend.SDK.WPF --passive
Another contrived example:
PsExec64.exe \\Target -u user -p password -h -c "filetoremoteexec.exe" filetoremoteexec.exe --flag param1 param2

Transfer files from Linux to Windows using pscp or some other tool

Problem Statement- I want to copy some files from remote machine (linux) to my windows machine. I know I can do it using pscp.
I tried looking on the internet, I found several articles, but in those articles I was not able to understand and I was having lot of problems in copying the files from Linx box to Windows.
Can anyone provide me step by step method here, so that I can follow that to transfer files. That will be of great help to me.
I am connected to host cli.vip.host.com using putty and that is linux with username- rkost and password as- password. And I want to copy file a.txt from linux to windows.
Download PSCP from below link
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Run PSCP
Got to command prompt
Use the below code
Copy single file
pscp user#host:remote_path/file_name host_path\file_name
eg: pscp user1#192.168.1.10:/home/user2/a.txt c:\Desktop\a.txt
Copy all files in a folder
pscp user#host:remote_path/* host_path\
eg: pscp user1#192.168.1.10:/home/user2/* c:\Desktop\test\
Copy all files & folders in a folder
pscp -r user#host:remote_path/ host_path\
eg: pscp -r user1#192.168.1.10:/home/user2/ c:\Desktop\test\
For this kind of problem I use all the time netcat. First, you start netcat as server on a machine with an ip IP_address, and afterwards you send the file from the other machine.
nc -l -p <port-number> > out_file
will start it as server in "listen" state, and will save what you send to it in the file "out_file".(check the man page of your version for more parameters.)
From the other machine you send the file something like this:
< file_to_send nc IP_address
(If you want to send an whole directory, you use tar )
I never used it under Windows (because I work as linux engineer). But you can find nc for windows, that work the same as in linux...
if you want to use pscp, you can do this:
pscp -pw password rkost#cli.vip.host.com:/path/to/file c:\path\
if this doesn't work try to add enviroment variable:
set PATH=C:\path\to\putty\directory;%PATH%
After installing POWERSHELL
wow64_microsoft-windows-powershell-exe
you can open the terminal and execute this command line
pscp -r -P Port user#IP:path WINDOWS path
example:
pscp -r -P 2222 user#MyDommain.com:/var/www/html C:\2023\HTML
Make sure you are connected to your vpn server, (i.e. cli.vip.host.com)
use following command from your windows machine
pscp -v rkost#remote_ip_addr:/path/to/file/a.txt c:/some_location/
you can see the verbose with -v flag.
If you wants to copy directory from remote linux machine to your windows
just refer my answer in this
PSCP copy files from godaddy to my windows machine

Resources