How to programatically pass a value to an R prompt (creating keyring) - r

I wanted to be able to execute this code as part of an initial configuration for using R on a Ubuntu
library(keyring)
keyring_create("system")
But I am then prompted for a password. Entering it manually is of course of no problem, but I wanted to do it programmatically.. and was trying something like
echo "mypasswd" | Rscript -e "library(keyring); keyring_create("system")"
But no luck,
Doesn't have to be bash, it can be an R only solution.. does anyone can give me a tip?
Thank you in advance

Related

How to get website information with unix

Using unix commands, how would I be able to take website information and place it inside a variable?
I have been practicing with curl -sS which allows me to strip out the download progress output and just print the downloaded data (or any possible error) in the console. If there is another method, I would be glad to hear it.
But so far I have a website and I want to get certain information out of it, so I am using curl and cut like so:
curl -sS "https://en.wikipedia.org/wiki/List_of_Olympic_medalists_in_judo?action=raw | cut -c"19-"
How would I put this into a variable? My attempts have not been successful so far.
Wrap any command in $(...) to capture the output in the shell, which you could then assign to a variable (or do anything else you want with it):
var=$(curl -sS "https://en.wikipedia.org/wiki/List_of_Olympic_medalists_in_judo?action=raw | cut -c"19-")

How to make SFTP cozbatch return different error codes

I need to get different SFTP exit codes for each error. For instance 'no such file or directory' --> exit code=552 or 550 instead of returning 1.
I've tried the following and it did not work:
//A05FTP EXEC PROC=SFTPROC,COND=(0,NE)
//COPSFTP.MYSTDIN DD *
host="xpto.xpty.xptz"
lzopts mode=text
cd /home/apl/files/unl
ls
a=`ls | wc -l`
echo `$a`
echo $?
QUIT
//*
and the output in spool is:
cozsftp> lzopts mode=text
mode=text
cozsftp> lzopts mode=text
mode=text
cozsftp> cd /home/apl/files/unl
Ý09.807¨ Invalid command.
cozsftp> a= 1
CoZBatchÝI¨: returning rc=exitcode=1
Can anyone help me?
COZBATCH allows you to embed shell scripts into JCL, so you don't need to use BPXBATCH. BPXBATCH really is a poor utility. If you're using Co:Z then good for you it rocks.
If you want to run shell commands you need to use the ! escape character.
!echo $a
FWIW, SFTP always returns 1 on error. I'm not sure if you can change that. Errors should be logged in the sysout.
Your problem may simply be the echo `$a`. Try enclosing with quotes instead of tick marks.
More generally, if you want to do more detailed error checking, instead of using the SFTP procedure (SFTPROC), I think you'd do better to write yourself a simple script that you execute with BPXBATCH. The script would issue the same SFTP commands, but you could capture and redirect the output (STDOUT/STDERR) and based on the return value ($?) and any error messages, you could certainly detect all the unusual conditions you might want.

Unix Shell Script: sleep command not working

i have a scenario in which i need to download files through curl command and want my script to pause for some time before downloading the second one. I used sleep command like
sleep 3m
but it is not working.
any idea ???
thanks in advance.
Make sure your text editor is not putting a /r /n and only a /n for every new line. This is typical if you are writing the script on windows.
Use notepad++ (windows) and go to edit|EOL convention|UNIX then save it. If you are stuck with it on the computer, i have read from here [talk.maemo.org/showthread.php?t=67836] that you can use [tr -d "\r" < oldname.sh > newname.sh] to remove the problem. if you want to see if it has the problem use [od -c yourscript.sh] and /r will occur before any /n.
Other problems I have seen it cause is cd /dir/dir and you get [cd: 1: can't cd to /dir/dir] or copy scriptfile.sh newfilename the resulting file will be called newfilenameX where X is an invisible character (ensure you can delete it before trying it), if the file is on a network share, a windows machine can see the character. Ensure it is not the last line for a successful test.
Until i figured it out (i knew i had to ask google for something that may manifest in various ways) i thought that there was an issue with this linux version i was using (sleep not working in a script???).
Are you sure you are using sleep the right way? Based on your description, you should be invoking it as:
sleep 180
Is this the way you are doing it?
You might also want to consider wget command as it has an explicit --wait flag, so you might avoid having the loop in the first place.
while read -r urlname
do
curl ..........${urlname}....
sleep 180 #180 seconds is 3 minutes
done < file_with_several_url_to_be_fetched
?

How can I get native Vi mode in R to be persistent?

I have looked at the answers to vi input mode in R? and vi mode to emacs mode while on R. Through the latter question, I learned that meta-ctrl-j will work to toggle vi-mode in R, but I cannot get it to stick so that every time I start R, vi-mode is enabled by default.
I have tried placing set editing-mode vi in my .inputrc, but that does not have the desired effect.
How can I get the vi-mode from meta-ctrl-j to be persistent across R sessions?
Try bind -f ~/.inputrc then bind -V | grep editing-mode and see if you get editing-mode is set to 'vi'.
If that works, it's just a matter of getting that file to be read on login.
Try echo $INPUTRC, if empty set it in your ~/.bashrc. Bash will supposedly check for ~/.inputrc then $INPUTRC then /etc/inputrc in search of your inputrc config.
Additionally, you might try adding bind -f ~/.inputrc to your ~/.bashrc if R opens up an interactive shell.

Merge vim system buffers

Is it possible to to do the following:
Terminal1: vim f1.txt
su someuser
Terminal2: vim f2.txt
I want to copy text from f1 in Termial1 as user A to f2 in Terminal2 as user someuser. I am using system buffer using "+y "+p commands it works great if I am with the same user.
Please help!
I just tried this without issue. The only difference is that I used "+gP instead of "+p.
Also, gave it a whirl in gvim without problem using point/click edit > copy and edit > paste.
So, maybe try "+gP or gvim?

Resources