首页 > 解决方案 > add answer to first commands question in shell script

问题描述

I have a first command in .sh file i.e.

cassandras3 backup --keyspace jl_powereasy_kespace --bucket database-backup-rds

This command asks a question when we run i.e.

Your cassandra data directory [/var/lib/cassandra/data]: 

how can I confirm this answer in shell script. I need to press enter for this confirmation automatically.

root@ip-172-31-2-150:/home/ubuntu# /bin/bash /var/cassandra_backupV1.sh
Your cassandra data directory [/var/lib/cassandra/data]: 

标签: bashshellubuntush

解决方案


As mentioned here, you can try running the command with echo as follows

echo -ne '\n' | cassandras3 backup --keyspace jl_powereasy_kespace --bucket database-backup-rds

or simply

echo | cassandras3 backup --keyspace jl_powereasy_kespace --bucket database-backup-rds

推荐阅读