When executing sudo, do not enter the password-the script is used. Do not use mongodo to directly close the password.

Source: Internet
Author: User

From: http://ifedora.diandian.com/post/2012-02-28/15816554

By default, the sudo command reads the password from the terminal device. Therefore, you must enter the password for each command to continue running. However, for scripts that require timed execution, you can only modify the sudo password reading method. The following is an example of a shutdown and a restart script:

Redirection (shutdown)

#! /Bin/bash

Sudo-s shutdown-H now <EOF

Password

EOF

Use pipelines (restart)

#! /Bin/bash

Echo password | Sudo-s shutdown-R now

The option-s (S in uppercase) means that the sudo command uses standard input instead of terminal input, so that the sudo command can read the password (password in the script) from the script ). However, both methods need to save the plaintext password in the script. If someone else sees the script, they will know the system password.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.