我想制作一个脚本并将其添加到快捷方式启动器...
当我双击该图标时,它会弹出一个终端窗口(完成)
在终端中,它首先会要求输入 root 密码,然后使用 root 权限做一些事情(我想把它作为一个函数)。
之后,在脚本结束时,它会像“按任意键关闭窗口”一样关闭窗口(我可以做到)
#!/bin/sh
touchpad(){
whoami
}
sudo -S touchpad # but it return error "command not found"
Run Code Online (Sandbox Code Playgroud)
如何以 root 用户身份运行功能或有其他方法来完成此操作?
编辑:
我试过这个 #!/bin/bash
sudo ./main2.sh #this did not work when I made it as a launcher
exit
Run Code Online (Sandbox Code Playgroud)
这是我当前的代码(谷歌搜索后):
#!/bin/bash
gksudo -m "Input Password" clear
sudo whoami
#sudo bla bla bla
read -n 1 -p "Press any key to close window"
Run Code Online (Sandbox Code Playgroud)
这就是我想要的,但是当我输入错误密码 3 次时出现错误。如果 gksudo 失败,如何强制退出主窗口?
我已经moreutils安装了whichprovided /usr/bin/parallel,这对我来说没有用。如果我现在想安装该软件包(GNU Parallel) ,我从这个答案parallel中了解到,它将把现有的重命名为./usr/bin/parallelmoreutils/usr/bin/parallel.moreutils
我想知道如果采取相反的做法会发生什么。例如,我parallel安装了该软件包,后来有人卸载moreutils并重新安装它,它会重命名/usr/bin/parallel为/usr/bin/parallel.gnu还是会得到什么名称?
如果重命名,如何避免这种情况?
我当前的 Ubuntu 版本是:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3
LTS Release: 18.04
Codename: bionic
Run Code Online (Sandbox Code Playgroud)
我还在其他机器上使用 Ubuntu 16.04。
我正在远程主机中并行运行一些查询命令,xargs该命令运行高效且运行良好,但在查找从哪个主机获取查询时遇到一些问题。
现在执行此操作的脚本部分如下所示:
export commands="cmd1; cmd2; "
hosts=("host1" "host2" "host3" "host4")
MaxInstance=10
echo_var(){
echo "Executing in $1:"; sleep 1; echo "Output of: $commands"; return 0;
}
export -f echo_var
printf "%s\n" ${hosts[@]} | xargs -n 2 -P $MaxInstance -I {} $(command -v bash) -c 'echo_var "$1"' _ {}
Run Code Online (Sandbox Code Playgroud)
其输出应如下所示,因为sleep 1:
Executing in host1:
Executing in host2:
Executing in host3:
Executing in host4:
Output of: cmd1; cmd2;
Output of: cmd1; cmd2;
Output of: cmd1; cmd2;
Output of: cmd1; …Run Code Online (Sandbox Code Playgroud)