I have a file that is locked/checked out exclusively by a user who is no longer with the company. I need to make changes and want to know how to "steal the lock".
Ask your perforce admin to remove the lock by issuing
p4 unlock -f <file>
PS: To reuse the departed user's license, your perforce admin might also want clean up the files left opened by him. He can revert the pending edits if they are useless or transfer them to another user via "p4 reopen".
The "reopen" and "revert after reopen" can also be performed by ordinary users.
"Locked" and "checked out" are two different things which require two different operations to undo. As Peter G. said, an admin can unlock a file with the unlock command:
p4 unlock -f <file>
However, to revert a file checked out by another user, you need to impersonate that user by passing their client (workspace name), host (computer name) and user names to the revert command, like so:
p4 -c theirclient -H theirhost -u theiruser revert filename
So if a Perforce user named jdoe has file foo.txt checked out in workspace ws1 on a host named joesPC, an admin can revert it with the following command:
p4 -c ws1 -H joesPC -u jdoe revert foo.txt
You have three choices, and if you don't know the user's password all three will require an admin.
p4 unlock -f filename
this will only work if you are an admin. Also, it will not work on files with a +l filetype, such as binary+l—in such a scenario it will need to be reverted.
With the user's password (get a p4 admin to clear it out if no one knows what it is), use a command like the one raven suggested:
p4 -c theirclient -H theirhost -u theiruser -p theirpassword revert -k filename
Or without the password, get an admin to use this sequence:
$ p4 login theiruser
User theiruser logged in.
$ p4 -c theirclient -H theirhost revert -k filename
Some dummy users may checkout the entire depot and lock all the files:
If you have admin access then you can use:
p4 client -d -f clientname
Where clientname is the name of the workspace.
I had similar issue on a file on my client. I was saying can't edit file, because opened on the same client. Wasted couple days waiting admin to unlock, but below worked for me:
p4 opened -x
p4 -c <client_name> unlock -x //filepath
Related
I am looking for some help to display a login banner when connecting to a remote server using SSH to display a message and then prompt the User with "yes or no". Only upon entering "yes" , the User should be prompted to enter the password during SSH.
I know login banners can be configured using /etc/issue.net and then uncommenting the line Banner in /etc/ssh/sshd_config followed by restarting SSH. However, If i want additionally SSH to prompt for accepting the policy banner after displaying the banner, how do i go about it ?
Thank you for your help in advance.
You could use something like this:
#!/bin/bash
cat /usr/share/agreement.txt
read -p "Do you accept? (y/n) " choice
if [[ $choice = y ]] ; then
/bin/bash
fi
Create the file /usr/share/agreement.txt with the contents of your agreement and make the script executable (using chmod +x).
Then edit /etc/passwd and set the command to run to the path of this script (for example /usr/share/agreement.sh).
How can I, as a simple user, change my own password with one command (in one line) in FreeBSD. I tried using passwd --stdin but that seems like it's a Linux command only.
Use the pw command to take input from STDIN like this:
echo "mynewpassword" | pw usermod admin -h 0
See man pw for more details.
Just type passwd and follow the prompts.
Also man 1 passwd for documentation.
Update with a copy of my comment, below, from September 2013:
The whole point about passwd is to make that hard for automated password changers to guess passwords. If you have a port like expect on the system you could script it. If you are root, you could use pw usermod username -h0. If you're just an ordinary user, just do it interactively.
I would like to use rsync via ssh to copy files from source-machine to dest-machine (both Linux boxes). Due to a security policy that is beyond my control, the files on dest-machine must be owned by user1 but user1 is not allowed to log in. I am user2 and can log in via ssh to both machines, user2 is in the same group as user1, and both users exist on both machines. After logging into either machine user1 can become user2 by first doing sudo -s (no password prompt) and then su user1.
The files typically have the following permissions:
source-machine:
-rw-rw-r-- user2 group1 file.txt
dest-machine:
-rw-rw-r-- user1 group1 file.txt
Rsync always changes the ownership on dest-machine to be user2, becuase I am using
/usr/bin/rsync -rlvx --delete --exclude-from ignore-file.txt --rysnc-path="/usr/bin/rsync" /path/to/files/ -e ssh user2#dest-machine.example.com:/path/to/files/
as part of the rsync command. At the moment, I have to work out which files have been copied and change the ownership back to user1.
I saw in this discussion that it may be possible to use
--rsync-path='sudo -u user2 rsync'
but I need the intermediate step of sudo -s.
Is there a way to get rsync to leave the files on dest-machine owned by user1?
UPDATE: Thanks to mnagel's comment, I tried that permutation, and when that didn't work, I was exploring why and added two more permutations: (1) I ran the script at source-machine as root and (2) I had somehow not included -go as options. (I hadn;t used -a, as the security policy doesn't allow preserving times). When put altogether, it works.
I am trying to connect to a remote host from my local host through the below command.But there was a setting in the remote host that soon after we login it will prompt to enter a badge ID,password and reason for logging in, because it was coded like that in profile file on remote-host How can I overcome those steps and login directly non-interactively, without disturbing the code in profile.
jsmith#local-host$ ssh -t -t generic_userID#remote-host
Enter your badgeID, < exit > to abort:
Enter your password for <badgeID> :
Enter a one line justification for your interactive login to generic_userID
Small amendment: to overcome remote server expect approach is required, but in case local script connects to bunch of remote servers, which configuration may be broken, just use SSH options:
ssh -f -q -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null USER#TARGETSYSTEM
This will omit ask for password in case there is no ssh_key setup, exit silently and continue with script/other hosts.
Puts ssh to background with -f, which is required when calling ssh command from sh (batch) file to remove local console redirect to remote input (implies -n).
Look into setting up a wrapper script around expect. This should do exactly what you're looking for.
Here are a few examples you can work from.
I have upvoted Marvin Pinto's answer because there is every reason to script this, in case there are other features in the profile that you need, such as Message of the Day motd.
However, there is a quick and dirty alternative if you don't want to make a script and you don't want other features from the profile. Depending on your preferred shell on the remote host, you can insist that the shell bypasses the profile files. For example, if bash is available on the remote host, you can invoke it with:
ssh -t -t generic_userID#remote-host bash --noprofile
I tested the above on the macOS 10.13 version of OpenSSH. Normally the command at the end of the ssh invocation is run non-interactively, but the -t flag allows bash to start an interactive shell.
Details are in the Start-up files section of the Bash Reference Manual.
I am creating a script file programmatically and call psftp.exe as follows:
psftp user#hostname.com -pw password -b psftpscript.txt
but it prompts for user input
The server's host key is not cached in the registry. You have no
guarantee that the server is the computer you think it is. The
server's rsa2 key fingerprint is: [ssh-rsa 1024 somekey]
If you trust this
host, enter "y" to add the key to PuTTY's cache and carry on
connecting. If you want to carry on connecting just once, without
adding the key to the cache, enter "n". If you do not trust this host,
press Return to abandon the connection. Store key in cache? (y/n)
I need it to be completely prompt free, automatic.
I tried -batch parameter but it just abandons the connection
I had the same problem with running a unattended script in Windows Server 2008's 'sandbox' like environment. I ended up running the following which enters the y at the prompt for you:
echo y | psftp user#hostname.com -l username -pw password -b psftpscript.txt
Hope this helps!
Note: I only had to run the echo y once and removing it for the 2nd run didn't ask for the key to be cached anymore.
When you run it the first time, it will show you your key for the server.
Copy the key and then on your command line, specify your host key like this:
psftp example.com -hostkey 06:15:d4:3b:e4:e8:23:c0:d6:6d:45:47:7e:bd:8d:74 -l yourusername -pw yourpassword -batch
You can create a file as input containing just a y and carriage return then run
psftp user#hostname.com -pw password -b psftpscript.txt < filename.txt
Thanks to James from http://www.sqlservercentral.com/Forums/Topic281954-9-1.aspx for such a simple solution
This doesn't answer your question directly, but provides a possible workaround:
Launch a command prompt as the user who will be running your script and manually accept the certificate. Then upon future connections, you won't have the issue.
Given your need, beyond what has been stated, this may or may not work. I came to this question with the same problem and ended up resolving it using the approach I've just described.
In .Net, I found that the above method didn't work quite as expected. The trick was to use .Net's built-in input redirection - and not the < operator. Here's what the code looks like now:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = "c:\\psftp.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.Arguments = strIP + " -v -l " + strUsername + " -pw " + strPassword + " -b " + strBatchFilename;
proc.Start();
StreamWriter myStreamWriter = proc.StandardInput;
myStreamWriter.WriteLine("Y\n"); //override the public key question <---
myStreamWriter.Close();
proc.WaitForExit();
proc.Close();
I had the problem where I didn't have the permission to delete \ rename file over the remote server and the files contains time stamp.
So I needed to download files by name.
The psftp can't accept params (or any way I was aware of) and I couldn't dynamically change the file names according to the current date.
So, from the batch file which I'm calling the psftp commands I created the commands dynamically and with the file with the relevant time stamp.
I could copy only the today files which is better the then copy everything each time.
cd "C:\Files"
echo cd outbound > C:\SFTP\temp.txt
echo mget file_%date:~10,4%%date:~4,2%%date:~7,2%*.csv >> C:\SFTP\temp.txt
echo quit >> C:\SFTP\temp.txt
echo close >> C:\SFTP\temp.txt
C:\SFTP\psftp user#ftp.address.com -b C:\SFTP\temp.txt
close
exit
The "echo cd outbound > C:\SFTP\temp.txt" cleaned the old file and start writing the content of the new file.
The "echo mget file_%date:~10,4%%date:~4,2%%date:~7,2%.csv >> C:\SFTP\temp.txt" resulted in creating the the command: "mget file_20151008.csv " which downloads all files which starts with "file_20151008..." the next 2 rows just ended the action and the line "C:\SFTP\psftp user#ftp.address.com -b C:\SFTP\temp.txt" execute it.
as results temp.txt looks like this:
cd outbound
mget file_20151008*.csv
quit
close
I ended up adding the key to cache by entering 'y' to the prompt. I had to do it only once, and after that no more prompts, it works good.
I think it should also be noted that if you are intending to use psftp in an unattended manner that you MUST include the -batch option. This will ensure that psftp does not provide any interactive prompts.
In the event user input would be required, psftp would abort. (e.g. ask user to cache host key, ask for password, etc.)
This will ensure that your process doesn't 'hang' and allow your automation to alert someone that there is an issue.
I think there is a problem with your command line.
Usage: psftp [options] [user#]host
Try:
psftp -pw password -b psftpscript.txt user#hostname.com
None of the above suggestions worked for me, but I did figure out something that DID work for me.
I made 2 entries in my batch file for it to work.
The first entry causes a connection to cache in the registry.
The second entry will connect automatically because now the hostkey is cached in the registry.
echo y | psftp.exe username#hostname.com -pw password
psftp.exe username#hostname.com -pw password -v -be -batch -b psftp_upload_command.bat