0

私の問題は、コマンドラインで「su -」と入力して、常にルートで手動でログインする必要があるスクリプトをルートから実行したいということです。

私の質問は、私が実行しているスクリプトが、パスワードの入力を求めるだけで自動的にルートでログインするということです。助けて!!!

::::::::::脚本:::::::::::::

if [ "$(whoami)" != "root" ]; then

echo -e '\E[41m'"\033[1mYou must be root to run this script\033[0m"

**su - # at this line I want to login as root but it is not working**

exit 1

fi

sleep 1

if [ "$(pwd)" != "/root" ]; then

echo -e '\E[41m'"\033[1mCopy this script to /root & then try again\033[0m"

cd /root

exit 1

fi

sleep 1

echo -e '\E[36;45m'"\033[1mDownloading Flash Player from ftp.etilizepak.com\033[0m"

sleep 2

wget -vcxr ftp://soft:S0ft\!@ftp.abc.com/ubuntu/ubuntu\ 12.04/adobe-flashplugin=/install_flash_player_11_linux.i386.tar.gz

cd ftp.abc.com/ubuntu/ubuntu\ 12.04/adobe-flashplugin/

sleep 1

echo -e '\E[42m'"\033[1mUnzipping .tar File...\033[0m"

sleep 1

tar -xzf install_flash_player_11_linux.i386.tar.gz

echo "Unzipping Compeleted"

sleep 2

echo -e '\E[42m'"\033[1mCopying libflashplayer.so\033[0m"

cp libflashplayer.so /usr/lib/mozilla/plugins/

:::::::::::::::終わり:::::::::::::::::::::

4

2 に答える 2

0

私の以前の回答に対するあなたのコメントによると、これが私がそれを行う方法です:

同じディレクトリに 2 つのファイルがあります。

-rwx------ 1 root root 19 Sep 10 13:04 test2.sh
-rwxrwxrwx 1 root root 29 Sep 10 13:06 test.sh

ファイル test.sh:

#!/bin/bash
# put your message here
su -c ./test2.sh

ファイル test2.sh:

#!/bin/bash
echo You run as:
whoami
# put your code here

結果:

> ./test.sh
Password:****
You run as:
root

このスクリプトのみのパスワード プロンプトを抑制したい場合は、「su -c」を「sudo」に置き換え、次の手順に従って sudoers ファイルを構成します: https://askubuntu.com/questions/155791/how-do-i -sudo-a-command-in-a-script-without-being-using-for-a-password

于 2013-09-10T11:18:21.837 に答える