在我的 node.js 脚本中,我需要使用 sudo 运行这两个命令:
execSync('sudo rsync -a ' + dir1 + " " + dir2);
execSync('sudo rm -Rf ' + dir1);
Run Code Online (Sandbox Code Playgroud)
但这会导致它会要求输入 sudo 密码两次;除此之外,如果我输入了错误的密码,脚本将继续运行而不会再次请求它;如何缓存密码以避免两次提示输入密码并等到提供正确的密码后再继续?
我正在尝试对目录下的所有日志文件执行 grep /var/log/application/archived/
而且我有 sudo 访问权限。像下面这样尝试给我错误
sudo grep 'checkThis' /var/log/application/archived/*.log
Run Code Online (Sandbox Code Playgroud)
错误
grep: /var/log/application/archived/*.log: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我尝试使用转义字符,但似乎不起作用
如果我给出任何一个文件名而不是 * 它会给我结果。
例如:sudo grep 'checkThis' /var/log/application/archived/firstLogFile.log 这给了我预期的响应
这是我第一次在我的系统上安装 linux,我觉得这里有很多乱七八糟的东西,当我尝试更新我的系统时遇到太多错误,当我使用终端和这个命令时,我感到很无助:
sudo apt update
Run Code Online (Sandbox Code Playgroud)
我特别从这 3 种类型中得到了很多错误:
知道我搜索了很多主题并且无法解决我的系统问题。
这是我在编写“sudo apt update”后得到的输出
Ign:1 cdrom://Ubuntu 17.04 _Zesty Zapus_ - Release amd64 (20170412) zesty InRelease
Err:2 cdrom://Ubuntu 17.04 _Zesty Zapus_ - Release amd64 (20170412) zesty Release
Please use apt-cdrom to make this CD-ROM recognized by APT. apt-get update cannot be used to add new CD-ROMs
Ign:3 http://download.videolan.org/pub/debian/stable InRelease
Ign:4 http://deb.torproject.org/torproject.org artful InRelease
Ign:5 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:6 http://download.videolan.org/pub/debian/stable Release
Ign:7 http://eg.archive.ubuntu.com/ubuntu zesty InRelease
Hit:8 http://archive.canonical.com/ubuntu artful InRelease …Run Code Online (Sandbox Code Playgroud) 我正在尝试安装 ffmpeg-libraries,但是,每次都会收到相同的错误消息。
我正在尝试为 discord.js 编写音乐机器人并需要 ffmpeg-libraries。我尝试重新安装 node.js(我使用的是当前的稳定版本)。
Louiss-MBP-2:backslashmoderation louisglen$ sudo npm i ffmpeg-binaries
Password:
lzma-native@3.0.8 install /Users/louisglen/Desktop/Discordjs/BackslashModeration/node_modules/lzma-native
node-pre-gyp install --fallback-to-build && node node_modules/rimraf/bin.js build
node-pre-gyp ERR! Tried to download(undefined): https://node-pre-gyp.addaleax.net/lzma-native/lzma_native-v3.0.8-node-v64-darwin-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for lzma-native@3.0.8 and node@10.15.0 (node-v64 ABI, unknown) (falling back to source compile with node-gyp)
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/louisglen/Desktop/Discordjs/BackslashModeration/node_modules/lzma-native/build'
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/louisglen/Desktop/Discordjs/BackslashModeration/node_modules/lzma-native/binding-v3.0.8-node-v64-darwin-x64/lzma_native.node" "--module_name=lzma_native" "--module_path=/Users/louisglen/Desktop/Discordjs/BackslashModeration/node_modules/lzma-native/binding-v3.0.8-node-v64-darwin-x64"
gyp ERR! …Run Code Online (Sandbox Code Playgroud) 您好,我正在尝试从虚拟环境中以 sudo 身份运行 python 脚本。
当我激活我的虚拟环境时,我通常会使用python somescript.py并且我的脚本以正确版本的 python 和所有内容启动
当我使用时sudo python somescript.py,我加载了错误的 python 安装,这不是我的环境中的安装。
我该如何解决这个问题?
为什么最后一个示例会抛出错误,而其他示例却可以工作?在任何情况下都会调用 Bash。
#!/bin/bash
function hello {
echo "Hello! user=$USER, uid=$UID, home=$HOME";
}
# Test that it works.
hello
# ok
bash -c "$(declare -f hello); hello"
# ok
sudo su $USER bash -c "$(declare -f hello); hello"
# error: bash: -c: line 1: syntax error: unexpected end of file
sudo -i -u $USER bash -c "$(declare -f hello); hello"
Run Code Online (Sandbox Code Playgroud) 所以我尝试在我的 ubuntu 和 ofc 上安装 jenkins 我确保通过运行更新系统: apt update
然后我尝试从 jenkins 网站运行以下命令来安装 jenkins :
”
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
Run Code Online (Sandbox Code Playgroud)
然后我收到一条错误消息:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package jenkins is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Linux 环境中打开一个新文件并写入一些内容。一般来说,操作目录需要 sudo 权限才能创建/写入新文件。在 perl 中我怎样才能以编程方式实现这一点?我希望使用 sudo 打开文件句柄,以避免权限被拒绝错误。
我很少看到关于此的旧帖子,但没有一个解决方案对我有用。我知道一种解决方案是使用 sudo 权限运行 perl 脚本,但我想执行在脚本内写入的操作,请建议
我的代码是这样的 -
open(my $fh, ">", $filename) or die "Could not open file '$filename' $!"; # Dies with the error
Run Code Online (Sandbox Code Playgroud)
我也尝试过
open(my $fh, '-|', 'sudo', '>', $filename) or die "Could not open file '$filename' $!"; # Asking for password
Run Code Online (Sandbox Code Playgroud) 我正在运行Ubuntu 11.10服务器并成功安装了Phusion Passenger.我尝试启动它时遇到以下错误:
christy@beast0:/$ passenger status
Phusion Passenger Standalone is not running, according to PID file /passenger.3000.pid
christy@beast0:/$ passenger start
Stopping web server.../home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/daemon_controller-0.2.6/lib/daemon_controller/lock_file.rb:63:in `initialize': Permission denied - /passenger.3000.pid.lock (Errno::EACCES)
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/daemon_controller-0.2.6/lib/daemon_controller/lock_file.rb:63:in `open'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/daemon_controller-0.2.6/lib/daemon_controller/lock_file.rb:63:in `exclusive_lock'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/daemon_controller-0.2.6/lib/daemon_controller.rb:269:in `stop'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/start_command.rb:466:in `block in stop_nginx'
from <internal:prelude>:10:in `synchronize'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/start_command.rb:463:in `stop_nginx'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/start_command.rb:94:in `rescue in run'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/start_command.rb:98:in `run'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/main.rb:93:in `block in run_command'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/main.rb:48:in `block in each_command'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/main.rb:43:in `each'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/main.rb:43:in `each_command'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/main.rb:91:in `run_command'
from /home/christy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/lib/phusion_passenger/standalone/main.rb:62:in `run!'
from …Run Code Online (Sandbox Code Playgroud) 在buildroot环境中,我将一个用户添加到组轮.现在我可以使用sudo以root权限执行命令.
它似乎有效,但当我尝试在我的RPi上导出一个引脚时,我总是得到Permission denied:
rpi:~$ sudo echo 4 > /sys/class/gpio/export
sh: can't create /sys/class/gpio/export: Permission denied
Run Code Online (Sandbox Code Playgroud)
这里是该目录的内容:
rpi:~$ ls -l /sys/class/gpio/
total 0
--w------- 1 root root 4096 Jan 1 00:00 export
lrwxrwxrwx 1 root root 0 Jan 1 00:00 gpiochip0 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
--w------- 1 root root 4096 Jan 1 00:00 unexport
Run Code Online (Sandbox Code Playgroud)
使用sudo获取root权限是否足以在导出文件中写入?我害怕所有者和团体.事实上,如果我输入:
rpi:~$ sudo chmod a+w /sys/class/gpio/*
Run Code Online (Sandbox Code Playgroud)
然后我可以成功导出引脚.但我不知道这是否是最好的方法.