I have a vi encrypted text file for storing the login details of DB. Now in my shell script I wanted to get the content say grep DB_NAME login_details.txt.
How do I pass the vi encryption password to the grep command ?
I believe everything is explained on this vim wikia page: http://vim.wikia.com/wiki/Encryption.
Read it whole (it warns you about when the file is actually encrypted, that the viminfo should be unset, etc...)
Especially is show how yo know the encryption used with :setlocal cm? ("show encryption method for the current file") and how to change it with :setlocal cm=... too.
But this is not interactive "per say" ... but you can use command line equivalent to have vim do this from the command line (which then can be used in a script), adding commands to just print the relevant line(s)
If you meant vi instead of vim, you need to specify which OS it is on, and look at vi encryption: what algorithm has been used?
This page shows 2 solutions depending on the type of OS used (And I'm quite sure there is a way to do the equivalent "on the fly", ie without having the decrypted file on disk... look for mcrypt -d --force ... (without specifying a destination file so it has to go to stdout. You need --force otherwise mcrypt refuses to output to stdout)
thing=$(echo '1,$'|vim --cmd "set key=${password}" ${filename} -es|grep needle)
This will load vim with the password and file read in from variables that you set previously somehow, and then dump the entire file contents to stdout, and then grep for the string "needle" and if it exists, it will be stored as the $thing variable.
This example is a bad practice, you should use existing tooling to accomplish secure decryption.
Related
vi version is BusyBox v1.20.2 (2014-08-27 12:48:18 PDT) multi-call binary, which run on esxi machine.
Can't paste text without auto indent by these methods:
:set paste in vi editor
configure set noautoindent in .vimrc which located in $HOME directory.
How could I achieve that?
BusyBox's vi is tiny and doesn't know what paste is.
It also isn't VIM, so won't read .vimrc, but will read $HOME/.exrc if it exists and is only owned and writable by the user. You should be able to put set noautoindent there in a more recent version.
You also have the option of placing commands in the EXINIT environment variable, or passing them as an additional parameter with -c "some_command" (both of which should be implemented in the version you're using, and both of which allow multiple commands separated by \n).
I'll note that all of the above depends on vi having been built with the SETOPTS, SET and COLON features enabled (though -c should work without COLON), which should be the default.
The set of options supported by a current version appears to be:
autoindent
expandtab
flash
ignorecase
showmatch
tabstop
I need to decrypt multiple files, in my batch file I have
--decrypt-files c:\PGP\unprocessed\*.pgp
but my script doesn't work. I receive
gpg: can't open c:\PGP\unprocessed*.pgp
instead, and I don't know why. --decrypt c:\PGP\unprocessed\filename.pgp works fine.
Another question is how to use --output when decrypting multiple files? Because when I try to combine two commands I receive an error message indicating that output doesn't work with this command.
For multiple files, the important are options
--multifile --decrypt
Work on CMD:
gpg --pinentry-mode=loopback --passphrase-file "C:\key.txt" --batch --ignore-mdc-error --skip-verify --multifile --decrypt "C:\\files\*.pgp"
The Windows command line is very limited in different ways, one is the lack of reasonable globbing: it does not expand ...\*.pgp to the actual files in that folder. Use a more capable shell (PowerShell, or install one of the shells from the unix world like bash using for example cygwin). Solutions for sticking with cmd.exe would be to pass the filenames through stdin (something like dir *.pgp | gpg --decrypt-files or writing a loop over all *.pgp files and decrypt them individually.
Latter would also help with the second part of your problem: --output can only define a single output; thus it does not work when multiple input files are passed.
I have a file loaded in R that I want to move to a samba share
It is something like
write(some-file, file = "|smbclient -U user //ip password")
It connects to the samba but then (I think) the output is "executed" in the smb: \> and I don't want the file to be executed, I don't know how to pass the file to the destination with a putfunction inside smbclient.
Edit: This is not the same problem as the first post. The first post is solved and answered by me. The point there was connecting to samba. Now I'm already connected to it but the write() function doesn't make a file, instead it pipes out the words separately. I just wanted to know how to make it create a file in a sentence.
I found the answer by changing the philosophy:
First, I write the file locally, like
write(some-file, there)
Then I use the system() function to call smbclient and put the file already written
system("smbclient -U user //ip/dir password -c \"put some-file some-file\"")
My script is more complex and it's inside a Shiny app but in summary that's the solution
I'm trying to make a script that hides some icons on desktop. When I run it line by line in command promt it works, but when I run the *.bat file in cmd it says "attributesi was unexpected at this time."
Here is the code:
set address=file.ext
set attributes=attrib %address%
for /F "tokens=*" %i in ("%attributes%") do set var=%i
set var=%var: =%
if %var:~1,1%==H (attrib -H %address%)else (attrib +H %address%)
Try this:
for /F "tokens=*" %%i in ("%attributes%") do set var=%%i
The for loop variables need %% instead of % when run in a batch file. But from the command line, % works just fine.
If you need any additional help with batch files, you should check out Rob van der Woude's pages on batch file scripting. It's a very rich resource on a language that's becoming increasingly difficult to find information on.
Speaking of which, I feel compelled to mention that Powershell scripting has largely replaced DOS batch file scripting (and for good reason). Almost anything you can do in a DOS batch file, you can now do easier in a Powershell script. Definitely worth checking into if you plan on doing more Windows-based scripting.
Hidedesktopicons.exe wasn't doing anything for me, but link that is given actually works. http://www.actualtools.com/forum/read.php?FID=8&TID=1072
Whenever I start a shell in vim using :sh, it doesn't source my ~/.bashrc file. How can I get it to do this automatically?
See :help 'shell'. You can set this string to include -l or --login, which will source your .bashrc file. So, you might have a line like this in your .vimrc:
set shell=bash\ --login
Note that this will alter everything that invokes the shell, including :!. This shouldn't be much of a problem, but you should be aware of it.
The value of this command can also be changed by setting the $SHELL environment variable.
If it doesn't source your .bashrc file, it may still source your .bash_profile file. I usually make one of them a symlink to the other. If your .bashrc performs some particularly odd one-time operations, you may have to edit it to only perform those operations with a login shell, but I've never had problems with it.
~/.vimrc
cmap sh<CR> !bash --login<CR>
If you quickly enter "sh<Enter>" in command-line, you can start bash with sourcing ~/.bashrc. So dirty.