gpt4 book ai didi

r - 需要 CentOS 脚本中的 SED 命令帮助以在 RStudio 包管理器中自动更新策划的 CRAN

转载 作者:行者123 更新时间:2023-12-04 19:31:43 24 4
gpt4 key购买 nike

我正在尝试为 RStudio 包管理器编写一个脚本以自动更新。
到目前为止我有这个

    #!/bin/bash

LOGFILE=/var/log/rstudio-pm.update.log

echo "`date '+%D %H:%M:%S'`: Starting rstudio-pm update." >> $LOGFILE

echo "`date '+%D %H:%M:%S'`: Synchronizing with CRAN." >> $LOGFILE
sync_result=`/opt/rstudio-pm/bin/rspm sync`
echo "`date '+%D %H:%M:%S'`: $sync_result" >> $LOGFILE
echo "`date '+%D %H:%M:%S'`: Completed synchronization with CRAN." >> $LOGFILE

echo "`date '+%D %H:%M:%S'`: Starting dryrun update." >> $LOGFILE
dryrun_result=`sudo /opt/rstudio-pm/bin/rspm update --source=my-cran`
echo "`date '+%D %H:%M:%S'`: $dryrun_result" >> $LOGFILE
echo "`date '+%D %H:%M:%S'`: Completed dryrun update." >> $LOGFILE

dryrun_result_last_line=`echo $dryrun_result| tail -n 1`





echo "`date '+%D %H:%M:%S'`: BEGIN ECHO OF DRY RUN RESULT LAST LINE" >> $LOGFILE

echo "`date '+%D %H:%M:%S'`: $dryrun_result_last_line" >> $LOGFILE

echo "`date '+%D %H:%M:%S'`: END ECHO OF DRY RUN RESULT LAST LINE" >> $LOGFILE







if [[ $dryrun_result_last_line =~ "--snapshot=" ]]
then
echo "`date '+%D %H:%M:%S'`: Starting actual update." >> $LOGFILE


param=`echo $dryrun_result_last_line | sed 's/.*\(--snapshot=[0-9]\+\).*/\1/'`


echo "`date '+%D %H:%M:%S'`:PARAMETERS FOR UPDATE $param" >> $LOGFILE

cmd="/opt/rstudio-pm/bin/rspm update --source=my-cran $param --commit"
echo "`date '+%D %H:%M:%S'`: Running: $cmd" >> $LOGFILE
update_result=`$cmd`
echo "`date '+%D %H:%M:%S'`: $update_result" >> $LOGFILE
echo "`date '+%D %H:%M:%S'`: Completed actual update." >> $LOGFILE
else
echo "`date '+%D %H:%M:%S'`: All packages already up to date." >> $LOGFILE

fi
我的命令需要如下所示:
sudo /opt/rstudio-pm/bin/rspm update  --source=my-cran --snapshot=2021-06-25 --commit
(--snapshot= 标志中的日期是我最终需要更改的变量。日期必须与 CRAN 的最新版本相对应
变量 $dryrun_result_last_line返回看起来像的文本

This action will add or archive the following packages: Name VersionPath License Needs Compilation Dependency Action broom 0.7.8 MIT +file LICENSE no true add checkpoint 1.0.0 GPL-2 no false addcolorspace 2.0-2 BSD_3_clause + file LICENSE yes false add curl 4.3.2MIT + file LICENSE yes false add dplyr 1.0.7 MIT + file LICENSE yesfalse add filelock 1.0.2 MIT + file LICENSE yes true add gert 1.3.1MIT + file LICENSE yes true add ggplot2 3.3.4 MIT + file LICENSE nofalse add ggsignif 0.6.2 GPL-3 | file LICENSE no false add glmnet4.1-2 GPL-2 yes false add lme4 1.1-27.1 GPL (>= 2) yes false add lpSolve 5.6.15 LGPL-2 yes true add mime 0.11 GPL yes false addopenxlsx 4.2.4 MIT + file LICENSE yes false add pkgcache 1.2.2 MIT +file LICENSE no true add pkgdepends 0.1.1 MIT + file LICENSE no trueadd plotly 4.9.4.1 MIT + file LICENSE no false add psych 2.1.6 GPL (>=2) no false add rio 0.5.27 GPL-2 no false add rmarkdown 2.9 GPL-3 nofalse add scatterD3 1.0.0 GPL (>= 3) no false add testthat 3.0.3 MIT +file LICENSE yes true add xfun 0.24 MIT + file LICENSE yes false addbroom 0.7.7 MIT + file LICENSE no archive checkpoint 0.4.10 GPL-2 noarchive colorspace 2.0-1 BSD_3_clause + file LICENSE yes archive curl4.3.1 MIT + file LICENSE yes archive dplyr 1.0.6 MIT + file LICENSE yes archive gert 1.3.0 MIT + file LICENSE yes archive ggplot2 3.3.3MIT + file LICENSE no archive ggsignif 0.6.1 GPL-3 no archive glmnet4.1-1 GPL-2 yes archive lme4 1.1-27 GPL (>= 2) yes archive mime 0.10 GPL yes archive openxlsx 4.2.3 MIT + file LICENSE yes archive plotly4.9.4 MIT + file LICENSE no archive psych 2.1.3 GPL (>= 2) no archive rio 0.5.26 GPL-2 no archive rmarkdown 2.8 GPL-3 no archive scatterD30.9.2 GPL (>= 3) no archive testthat 3.0.2 MIT + file LICENSE yes archive xfun 0.23 MIT + file LICENSE yes archive To complete thisoperation, execute this command with these flags:'--snapshot=2021-06-25 --commit'.


我需要把 2021-06-25 从上面拉出来
我怎样才能做到这一点。在我的日志文件中,我的 $param变量只返回 --snapshot=2021
我怎样才能让它返回 2021-06-25 的完整日期?
谢谢你

最佳答案

How can I make it return the full date of 2021-06-25?


简短回答:要在匹配中包含连字符,请将其包含在括号表达式中,即 i。 e. [0-9-] .
如果您更感兴趣:您的 $dryrun_result_last_line不只包含 $dryrun_result 的最后一行因为 echo $dryrun_result丢失换行符;要保留它们,您必须引用:
dryrun_result_last_line=`echo "$dryrun_result" | tail -1`
如果你的 shell 支持 <<<重定向,您还可以使用:
dryrun_result_last_line=`tail -1 <<<$dryrun_result`
甚至
dryrun_result_last_line="${dryrun_result##*
}"

关于r - 需要 CentOS 脚本中的 SED 命令帮助以在 RStudio 包管理器中自动更新策划的 CRAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68166200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com