[Linux](EN) Use or pass sudo password in shell script

Process file or result of command in while loop line by line in shell script.


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)


Solution

  • Use -S option and |
echo "PASSWORD" | sudo -S apt-get update
  • Usage with file
cat << EOF > password.txt
> PASSWORD
> EOF

cat password.txt | sudo -S apt-get update


  • Use --stdin option and |
echo "PASSWORD" | sudo --stdin apt-get update
  • Usage with file
cat << EOF > password.txt
> PASSWORD
> EOF

cat password.txt | sudo --stdin apt-get update

Reference

[AWS] AWS CLI를 이용해 EC2 인스턴스를 생성, 나열 그리고 삭제하기

> AWS CLI를 통해서 EC2 인스턴스를 생성, 나열 그리고 삭제를 해보자.## 환경- Ubuntu 18.04- AWS CLI- Bash shell(/bin/bash)## 과정1. AWS CLI 설치2. 기본 환경 설정(구성 및 자격 증명 설...… Continue reading