I have written a bash script for my office usage to fetch some information from the devices using sshpass
along with ssh
command. As we know sshpass
allows a password to be passed on the command line using -p
option, which makes the password visible hence I want a password that needs to be prompted as user input on the screen itself.
The below script works fine, but I need a password to be prompted on the screen for user input. Please advise how this can be done, as I have googled around but did not get any concrete answer.
#!/bin/bash
#
# timestamp to be attached to the log file
TIMESTAMP=$(date "+%Y%m%d%H%M%S")
# logfile to collect all the Firmware Version of C7000 components
LOGFILE="/home/myuser/firmware_version-${TIMESTAMP}.log"
for host in $(cat enc_list);
do
echo "========= $host =========";
sshpass -p my_password timeout -t 20 ssh -o "StrictHostKeyChecking no" $host -l tscad show firmware summary ;
done | tee -a "${LOGFILE}"