how to login and download file using perforce command line - command-line

I have to download a file daily from perforce depot.
Presently I do it manually by selecting that file and using "Get latest version" option.
I want to write a script which I will schedule in my windows task schedular to get the file daily.
Please help me/guide me how to do this task automatically.
I am using p4v client software in windows XP operating system.

Using P4V will make it hard to automate. I suggest you use the command-line client, p4.exe, instead. If there's only one file that you need the contents of you could simply use "p4 print" and avoid the need for creating a workspace (client) spec, e.g:
p4 print -o <local filename> //depot/path/to/file
Note that the above command requires you to be already logged on to the Perforce server. There's at least two ways around this:
1) Specify the username and password on the command-line (not really recommended for security reasons):
p4 -u myuser -P mypasswd print -o <local filename> //depot/path/to/file
2) Use a dedicated background user for the task, with an unlimited login expiration time (see p4 group and the Timeout field):
p4 -u backgrounduser print -o <local filename> //depot/path/to/file
A licensed "background user" designated for only performing automated tasks can be obtained at no further cost from Perforce Software. Try contacting Perforce support and ask them about this.

In a bat you can use the p4.exe commandline tool that comes with p4v and issue the sync command:
p4 sync myFileThatINeedToGetDaily.txt

Before Issuing Sync, make sure you have logged in and set the port and client view
p4 -u myuser -P mypasswd
p4 set P4PORT=server:nnnn
p4 sync file1.txt

The command you need is p4 sync.

Related

Create a installer with inno setup and postgreSQL in Windows X64

I've created an installer for my application that also installs postgreSQL.
The first question:
What is the best way to configure my database, I mean, is it better to use the postgres default user account? Or should I create a new user. Also is it better to use default public schema or should I create a new schema? As one can see, I'm seeking the best practices to use databases. Also, what kind of care do I need to take with possible already installed versions of postgreSQL from any other application?
The second question:
How to create a user using the installer?
I'm trying to create a new user different from the default user but how can I set a password for this user? I would like to do this without prompting the user in a command shell.
If it's helpful, I will happily post any of my code!
Let's go for some points that you've asked in your question.
What is the best way to configure my database, I mean, is it better to use the postgres default user account?
That doesn't matter at all as long as you have defined a strong password for the user to install it you will be good.
is it better to use default public schema or should I create a new schema?
That will depends on your software. If you want to have everything well defined and organized on the use of the database go on, create a schema to your system. If your system will be the only one using PostgreSQL why botter? Read this answer on this matter from DBA forum PostgreSQL and default Schemas
Also, what kind of care I might to take with possible already installed versions of postgreSQL of any other application?
That's a trick one and the very first problem you will have. I find out the hard way that you can't install PostgreSQL database if you already have one previously installed. Not even if you uninstall it (in this case you have to delete all associated registries from windows registry of PostgreSQL).
My advice here is that you put a message on your installer that your system needs a fresh install of PostgreSQL on the target machine and it can't have a previously installed one on it otherwise the install will fail. I know that sucks, but I couldn't find anything to do here. One other thing that I did was to add a note on the installer messages to the user that if He still want to install the system on that machine He would have to contact the "support" to do it manually.
How to create a user using the installer?
From here I will add some commands to you install PostgreSQL in unattended mode.
I'm trying to create a new user different from default user but how to set a password to this user?
The command you will need to install PostgreSQL with a user different from the default one will be:
postgresqlInstallFile[withversion].exe --mode unattended --superaccount super_user_name --superpassword yourStrongPassowordHere
It would be great here if you could ask for the password on your installer program and use a variable within above command.
That alone will install the database with a user defined by you. Here is the documentation about all parameters for PostgreSQL Unattended Install
The second problem is regarding the database of you system. The best course of action I could find was to make a Dump file from the database that I need to install (this database would be empty, with just the structure), added this dump file to the installer so I could import it to the fresh installation of the database.
The problem with this approach is you can't create a database or restore it to PostgreSQL without entering the password for the super account. What I did was
Add messages to the user that He should pay attention to the installer messages and steps so he can't get it wrong
After installing PostgreSql database comes the step to create the database so I use the command:
[path_for_postgresq]/createdb.exe -U user_you_created -W -E UTF8 -O user_you_created "NameOfYourDatabase"
Before I run the above command I showed a message to the user that he will see a prompt screen asking for a password, so He have to enter it and hit Enter. You can't add it as a parameter (PostgreSQL says it is for security measures)
After the database creation it is time to import the dump that I've added on the installer so I used:
[path_for_postgresq]/pg_restore -U user_you_created -c -d NameOfYourDatabase DumpFileOfYourDatabase.backup
Once again, before this command I showed a message to the user asking to enter the password for the database restore command.
Here I will add the code I made for the NSIS installer. Just the PostgreSQL part of it. There are a lot more on my installer you may need something more.
;--------------------------------
;Include Modern UI
!include "MUI.nsh"
;Include Process checker
!include nsProcess.nsh
;Include ZipDLL
!include zipdll.nsh
; include for some of the windows messages defines
!define ALL_USERS
!include winmessages.nsh
;--------------------------------
;General Configuration
Name "Name of your Installer"
OutFile "fileNameOfYourInstaller.exe"
ShowInstDetails "show"
InstallDir $PROFILE\FolderWhereToInstallYourSystem
; Request application privileges for Windows Vista
RequestExecutionLevel admin
; HKLM (all users) vs HKCU (current user) defines
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!define env_hkcu 'HKCU "Environment"'
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
Function .onInit
SetOutPath $TEMP
# the plugins dir is automatically deleted when the installer exits
InitPluginsDir
File /oname=re.bmp re.bmp #here is an image for a splash screen of the installer
splash::show 2000 re
Pop $0 ; $0 has '1' if the user closed the splash screen early,
; '0' if everything closed normally, and '-1' if some error occurred.
FunctionEnd
Function verifyInstallationDIR
IfFileExists $INSTDIR PathGood
MessageBox MB_OK "The chosen directory is not valid for installation.$\r$\nPlease start again and inform a valid path."
Quit ;if $INSTDIR wasn't created the installer will close
PathGood:
FunctionEnd
Section
SetOutPath $TEMP
CreateDirectory $INSTDIR
#Message to the user to PAY ATTENTIOM
MessageBox MB_OK "Please carefully read all messages through installation steps!"
Call verifyInstallationDIR
#Files needed to the installer
File "resources\DatabaseDumpFile.backup"
File "resources\postgresql-9.3.9-3-windows-x64.exe"
#Call postgresql installation in an unattended mode
ExecWait 'postgresqlInstallFile[withversion].exe --mode unattended --superaccount super_user_name --superpassword yourStrongPassowordHere'
Postgresql_Running_Check:
; is app.exe process running? result is stored in $R0
${nsProcess::FindProcess} "postgres.exe" $R0
${If} $R0 > 0
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "PostgreSQL process is not running yet. Wait 30 seconds and click Retry or Cancel to cancel installation." /SD IDCANCEL IDRETRY Postgresql_Running_Check
Quit
${EndIf}
;Create the database
MessageBox MB_OK "The System DataBase will be created. A console window will appear asking for a password. Please when it happens type:$\r$\n$\r$\nyourStrongPassowordHere"
ExecWait '$PROGRAMFILES64\PostgreSQL\9.3\bin\createdb.exe -U user_you_created -W -E UTF8 -O user_you_created "NameOfYourDatabase"'
MessageBox MB_OK "The System Installer will import the configuration data to the database. It will ask again for the password. Please when it happens type:$\r$\n$\r$\nyourStrongPassowordHere"
ExecWait '$PROGRAMFILES64\PostgreSQL\9.3\bin\pg_restore -U user_you_created -c -d NameOfYourDatabase DatabaseDumpFile.backup'
SectionEnd
Hope it helps.

How to delete P4 client saved on my local workspace in Eclipse?

I want to delete the client dpi-sigs which I created on my windows machine, I tried to remove the directory but nothing happened.
From the command line this will do it:
p4 client -d dpi-sigs

remote svn update on server farm

I wrote an svn hook that triggers upon commit. The goal is to automatically
update multiple servers by running svn update on each.
So my server topology consists of (all running under Windows 2012):
a) SVN_server
b) server1,...,N
I use PsExec to invoke svn update from SVN_server to server1,...,N
As the updated directory is used by the web server (IIS) some files may be
in use at the time of the svn update, so I would expect it to fail occasionally.
What happens though, is that intermittently the svn update hangs! When inspecting with ProcessExplorer I see that psExec runs svn update which in turn runs a child process under the name of "conhost". I assume this would be some interactive prompt but I have no way of redirecting standard output to a file in order to investigate further.
FYI, the post-commit.bat hook (on repository mysite) looks like:
:: first update SVN_server working folder
svn update d:\websites\mysite
:: then update server1,..,N
cmd /c c:\tools\PsExec.exe -i -u Admin -p Passw \\swWeb01 -h c:\tools\svn update d:\websites\mysite
cmd /c c:\tools\PsExec.exe -i -u Admin -p Passw \\swWeb02 -h c:\tools\svn update d:\websites\mysite
how can I redirect stdout/stdin in the remote svn update?
after killing the blocked svn update process the svn directory becomes dirty.
I have to use svn cleanup to recover. Any ideas why this is happening and how can I resolve it?

Script to add group/user to "log on as a service"

I am trying to create a script that add a certain user/group to "log on as a service" in my Windows 2008 box. However I have tried using the ntrights.exe, downloaded it and ran the line ntrights +r SeInteractiveLogonRight -u CSSGroup in cmd but it failed because of the incompatibility.
Can someone help me or point me in any other useful direction?
These things are stored in the registry. Only System has access. So use psexec
psexec -s -i <your script>
to run script as system giving you access to the security info (which you'll have to turn on and compare to regkeys when turned off as they are in binary structures).
You can also take ownership of the keys and give yourself permission to access.
HKEY_LOCAL_MACHINE\SECURITY

Powershell_script resource throws error: "Your session has expired, please login again."

I am trying to use Chef to pull a file from Perforce, by calling p4 sync from a PowerShell script. As the title indicates, I am being plagued with this failure: "Your session has expired, please login again." From what I have gathered, it has something to do with the way the PowerShell script is run through Chef (using Invoke-Command?)
Here's what I have that is not working :(
powershell_script 'P4Sync' do
cwd "C:\\Program Files\\Perforce"
code <<-EOH
&".\\p4.exe" set P4PORT=server:1234
&".\\p4.exe" set P4USER=AUTOMATION_USER
set shallNotPass 'AUTOMATION_USER_PASSWORD_TICKET'
&".\\p4.exe" -d c:\\temp -P $shallNotPass client -o | &".\\p4.exe" -P $shallNotPass client -i
set rootdir '//root/scripts'
&".\\p4.exe" -P $shallNotPass sync $rootdir/script.bat
&".\\p4.exe" -P $shallNotPass sync $rootdir/script.sh
EOH
end
The other powershell_script resources that I have used (which are working) involve only PowerShell cmdlets, and not external executables.
Any suggestions would be appreciated! Also, if you care to share any other resources where I might have found this information on my own, it would also be helpful. I've spent quite a bit of time hunting the internet on this error, and haven't had much luck.
The error message is a Perforce authentication failure and suggests there's a problem with your AUTOMATION_USER_PASSWORD_TICKET. If that's actually a ticket (it should look like a hash rather than plaintext), the problem is most likely that it's expired -- by default a login ticket is only valid for 12 hours after the "p4 login" command used to acquire it.
See the documentation for "p4 login" for more on how tickets work:
http://www.perforce.com/perforce/r15.1/manuals/cmdref/p4_login.html
The easiest solution is probably to put AUTOMATION_USER in a group with an unlimited Timeout, then re-run "p4 login" to get a new ticket (which will never expire) and put that in your script.