如何每小时运行一个脚本,有一些需要密码的命令?

问题描述 投票:1回答:2

我正在使用云桌面并尝试执行./parseScript.sh,其中包含以下命令:

我想通过使用以下命令每小时调用此脚本:

Step 1. Connect to your cloud desktop using ssh.
Step 2. Run these commands:
% screen
% while true; do ./parseScript.sh; sleep 3600; done
Step 3. Close the window with the running command.
Step 4. (same as Step 1) Connect to your cloud desktop using ssh.
Step 5. Run this command: screen -R. You will get back to the session you left in step 3.

现在的问题是在我的脚本中我有上面提到的1个命令,必须使用sudo -u identmon执行,因此每次都会要求输入密码,无论如何除了手动之外每小时运行一次这个脚本吗?

bash sudo gnu-screen
2个回答
0
投票

最简单的方法是添加qazxsw poi选项你的sudoers文件你可以在这里查看qazxsw poi

NOPASSWD

那说小心你添加一个无密码sudo。


0
投票

您可以使用bash的https://askubuntu.com/questions/147241/execute-sudo-without-password自动化脚本。将密码存储在某个变量中。 username ALL=(ALL) NOPASSWD: ALL 将在运行时自动为脚本提供密码。

© www.soinside.com 2019 - 2024. All rights reserved.