gpt4 book ai didi

linux - 如何将密码作为参数传递给 shell 脚本

转载 作者:IT王子 更新时间:2023-10-29 01:13:45 25 4
gpt4 key购买 nike

我正在通过 ansible-playbook 自动安装 sage。因为我需要运行两个 shell 脚本。这是第一个 shell 脚本的样子:

#!/bin/bash
# Creating Sage notebook

dir="/root/.sage/sage_notebook.sagenb"
screen -S "Sage_Server" sage -c 'notebook(interface="", directory=$dir, port=80, accounts=true)'

这是第二个 shell 脚本的代码:

#!/bin/bash
# Creating Sage inotebook

address=$(hostname --ip-address)
sage -c "inotebook(interface=" "'$address'" ",port=80,accounts=true)"

剧本是这样的:

---
- hosts: localhost
remote_user: root

tasks:
- name : update system
apt : update_cache=yes

- name : install m4
apt : name=m4 state=present

- name : install build-essential
apt : name=build-essential state=present

- name : install gcc
apt : name=gcc state=present

- name : install gfortran
apt : name=gfortran state=present

- name : install libssl-dev
apt : name=libssl-dev state=present

- name : install python-software-properties
apt : name=python-software-properties state=present

- name : add sage ppa repo
apt_repository: repo='ppa:aims/sagemath'

- name : update system
apt : update_cache=yes

- name : install dvipng
apt : name=dvipng state=present

- name : install sage binary
apt : name=sagemath-upstream-binary state=present

- name : invoke create_sagenb script
command: /usr/bin/screen -d -m sudo /root/databases-and-datamining-iiith/python-scripts/create_sagenb -i -y

- name : invoke start_sage script
command: /usr/bin/screen -d -m sudo /root/databases-and-datamining-iiith/python-scripts/start_sage -i -y

现在,当我运行第一个脚本时,它要求输入一个新的 sage 密码,可以是任何内容。但我无法从剧本中传递该密码。不过,如果我这样做

ps -ef | grep sh

我可以看到脚本正在运行,但 sage 服务没有运行。它需要密码才能启动服务。

谁能告诉我如何通过命令将密码作为参数提供给 shell 脚本。

最佳答案

我不知道 sage 也不知道如何以其他方式提供密码,但是如果程序要求输入密码,您可以使用 expect建议here .

关于linux - 如何将密码作为参数传递给 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32271258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com