{"id":4575,"date":"2018-01-09T06:21:45","date_gmt":"2018-01-09T06:21:45","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=4575"},"modified":"2025-02-01T22:39:32","modified_gmt":"2025-02-01T22:39:32","slug":"ways-to-pass-password-in-triggers-file-or-script-file-in-perforce","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/ways-to-pass-password-in-triggers-file-or-script-file-in-perforce\/","title":{"rendered":"Ways to Pass Password in Triggers file or Script file in Perforce"},"content":{"rendered":"<p><strong>Option 1<\/strong><br \/>\nIf your Perforce server is set to security level 2 or lower you can have your trigger script run as the same user every time (typically a &#8220;background&#8221; user). Then, either have the server&#8217;s P4PASSWD environment variable set to the background user&#8217;s password,<\/p>\n<p><strong>Option 2<\/strong><br \/>\nYou can also use the -P flag to specify the password with the P4 commands issued by the script.<\/p>\n<p><strong>Option 3<\/strong><br \/>\nYou can echo the password and pipe it to the login command. Note that there is no space between the password and the pipe symbol.<\/p>\n<p>echo &lt;password&gt;| p4 login<\/p>\n<p><strong>Option 4<\/strong><br \/>\nIf you do not want to place a password in the script, you can use a text file containing the password. Make sure this password file has appropriate read and write privileges.<\/p>\n<p>p4 login &lt; password.txt<\/p>\n<p><strong>Option 5<\/strong><br \/>\nA more secure method is to use ticket based authentication and a group to keep a background user &#8220;logged in&#8221; at the Perforce server:<\/p>\n<p>1. Create a group:<\/p>\n<p>p4 group always_on<\/p>\n<p>2. Add your background user to the &#8220;Users&#8221; field.<\/p>\n<p>3. Change the timeout from the default setting (12 hours), which is set in seconds. The new value depends on the server version:<\/p>\n<p># 2008.1 and later: Set this value to &#8220;unlimited&#8221;. A timeout value of zero is no longer accepted.<\/p>\n<p># 2005.1 to 2007.3: Set this value to zero.<\/p>\n<p># 2004.2 and earlier: Set this to a very large value &#8212; but not too large, as some server versions do not handle situations where the timeout is set to exceed the &#8220;Unix Epoch&#8221;, which is approximately in the year 2038. A safe value is 315532800 seconds, which is about 10 years.<\/p>\n<p># Save the group.<\/p>\n<p># In your trigger script, log the background user in and run the trigger once.<\/p>\n<p>echo password| p4 -p server:port -u username login<\/p>\n<p># If the trigger runs properly, you can remove the password line.<\/p>\n<p>The user now remains logged in. Since this is ticket based authentication, they remain logged in even if the server is shut down or the hardware is rebooted.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Option 1 If your Perforce server is set to security level 2 or lower you can have your trigger script run as the same user every time (typically a &#8220;background&#8221;&#8230; <\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[370],"tags":[534,373,2941,4492],"class_list":["post-4575","post","type-post","status-publish","format-standard","hentry","category-perforce","tag-password","tag-perforce","tag-perforce-triggers","tag-trigger-script"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=4575"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4575\/revisions"}],"predecessor-version":[{"id":4576,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4575\/revisions\/4576"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=4575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=4575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=4575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}