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.